Skip to content

Miri does not check all offset_from conditions #1950

Closed
rust-lang/rust
#94827
@RalfJung

Description

@RalfJung

offset_from currently requires that:

Both the starting and other pointer must be either in bounds or one byte past the end of the same allocated object.

However, Miri fails to check this condition -- the following program should error, but it does not:

fn main() {
    let start_ptr = &() as *const ();
    let length = 10;
    let end_ptr = (start_ptr as *const u8).wrapping_add(length) as *const ();
    unsafe { (end_ptr as *const u8).offset_from(start_ptr as *const u8); }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-shimsArea: This affects the external function shimsC-bugCategory: This is a bug.I-misses-UBImpact: makes Miri miss UB, i.e., a false negative (with default settings)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions