Skip to content
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

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

Closed
saethlin opened this issue Jun 16, 2024 · 1 comment · Fixed by #3682
Closed

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

saethlin opened this issue Jun 16, 2024 · 1 comment · Fixed by #3682
Labels
C-bug Category: This is a bug. I-ICE Impact: makes Miri crash with some ICE

Comments

@saethlin
Copy link
Member

saethlin commented Jun 16, 2024

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:

let layout = Layout::from_size_align(size, align).unwrap();

@saethlin saethlin added C-bug Category: This is a bug. I-ICE Impact: makes Miri crash with some ICE labels Jun 16, 2024
bors added a commit to rust-lang-ci/rust that referenced this issue Jun 16, 2024
Add a precondition check for Layout::from_size_align_unchecked

Ran into this while looking into rust-lang/miri#3679. This is of course not the cause of the ICE, but the reproducer doesn't encounter a precondition check and it ought to.
@RalfJung
Copy link
Member

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.

@bors bors closed this as completed in 28aa08e Jun 17, 2024
bors added a commit to rust-lang-ci/rust that referenced this issue Jun 18, 2024
Add a precondition check for Layout::from_size_align_unchecked

Ran into this while looking into rust-lang/miri#3679. This is of course not the cause of the ICE, but the reproducer doesn't encounter a precondition check and it ought to.
bors added a commit to rust-lang-ci/rust that referenced this issue Jun 20, 2024
Add a precondition check for Layout::from_size_align_unchecked

Ran into this while looking into rust-lang/miri#3679. This is of course not the cause of the ICE, but the reproducer doesn't encounter a precondition check and it ought to.
RalfJung pushed a commit to RalfJung/rust that referenced this issue Jun 29, 2024
show proper UB when making a too large allocation request

Fixes rust-lang/miri#3679
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. I-ICE Impact: makes Miri crash with some ICE
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants