-
Notifications
You must be signed in to change notification settings - Fork 59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Miri allows inbounds offsets outside of provenance but inside of the allocid #349
Comments
Slightly cleaner trace by using intrinsic #![feature(core_intrinsics, raw_ref_op)]
use std::intrinsics::offset;
#[allow(unused_must_use, clippy::no_effect)]
fn main() {
unsafe {
// alloc id 2200, tag 4409
let place = [0u8; 5];
// tag 4410 at alloc2200[0x0..0x1]
let p = &raw const place[0];
let q = offset(p, 4); // not diagnosed ub
// attempting a read access using <4410> at alloc2200[0x4]
*q; // ub
}
} trace
|
It is fully intended. In fact the "subobject" part of Stacked Borrows is more a case of emergent behavior than anything that was deliberately put in. And note that "subobjects" in the Stacked Borrows sense do not have to be contiguous; it is perfectly possible for a ptr to be valid for some put not all fields of a struct. The docs are IMO pretty clear about it since they always talk about allocation boundaries, never about whether the aliasing model allows the ptr to be used here or there. |
I think the docs are clear here and nobody objected to this being intentional, so I am closing this issue. If someone wants to strengthen the |
IMO, this issue should be subject to a T-opsem FCP on the question "is it defined behaviour to offset within the allocation entirely" prior to being closed. Otherwise, I have no objections. |
This is documented on a stable function. I wouldn't expect us to FCP something like that. Why would we re-FCP an unsafe contract that has already been approved by libs/lang? |
Since opsem can't pick a different answer without throwing a breaking change at the greater rust community there isn't much point in a full FCP. |
Edit: Actually, wait, the consistency issue I have is the other way arround, that |
That should currently be the case (and is still the case under all proposals I am aware of). |
Yeah, that isn't implicated here. The opposite one is, but is very much not the case anyways. I withdraw my concern. |
... and it is unclear whether this is intended (inbounds only cares about the allocated object bounds) or a bug (inbounds should respect subobject provenance).
pointer::offset
saysand
ptr::read
saysExample:
Tracking:
trace
The text was updated successfully, but these errors were encountered: