rust-lang / miri

An interpreter for Rust's mid-level intermediate representation
Apache License 2.0
4.13k stars 318 forks source link

Trying to allocate isize::MAX + 1 bytes ICEs Miri #3679

Closed saethlin closed 1 week ago

saethlin commented 1 week ago

This program (reduced from an ICE encountered when running the tests for https://crates.io/crates/tinyset):

fn main() {
    let bytes = isize::MAX as usize + 1;
    unsafe {
        let layout = std::alloc::Layout::from_size_align_unchecked(bytes, 1); // Undetected library(?) UB here
        let _ = std::alloc::alloc_zeroed(layout);
    }
}

Hits this ICE:

thread 'rustc' panicked at src/tools/miri/src/alloc_bytes.rs:71:59:
called `Result::unwrap()` on an `Err` value: LayoutError

Caused by this unwrap: https://github.com/rust-lang/miri/blob/60a720040d6c60656ab9cac0980e587d19d9c07a/src/alloc_bytes.rs#L71

RalfJung commented 1 week ago

That's kind of expected, Miri does not make any attempt to handle OOM or too big allocations. But probably it shouldn't be that unwrap that signals that.