Skip to content

miri reports allocation of size 0 in in Thinbox::new()  #96485

Closed
@matthiaskrgr

Description

@matthiaskrgr

I tried this code:

#![feature(thin_box)]

use std::boxed::ThinBox;
fn main() {
    let _thin_concrete_error: ThinBox<Foo> = ThinBox::new(Foo);
}

struct Foo;

cargo miri run

error: Undefined Behavior: creating allocation with size 0
  --> /home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc/src/alloc.rs:89:14
   |
89 |     unsafe { __rust_alloc(layout.size(), layout.align()) }
   |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ creating allocation with size 0
   |
   = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
   = help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information

   = note: inside `std::alloc::alloc` at /home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc/src/alloc.rs:89:14
   = note: inside `std::boxed::thin::WithHeader::<()>::new::<Foo>` at /home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc/src/boxed/thin.rs:159:23
   = note: inside `std::boxed::ThinBox::<Foo>::new` at /home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc/src/boxed/thin.rs:52:19
note: inside `main` at src/main.rs:5:46
  --> src/main.rs:5:46
   |
5  |     let _thin_concrete_error: ThinBox<Foo> = ThinBox::new(Foo);
   |                                              ^^^^^^^^^^^^^^^^^

note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace

error: aborting due to previous error

Technically miri already shows that the code is unsafe-wrapped. Maybe it needs some special handing of Thinbox?

miri 0.1.0 (a71a008 2022-04-25)

Metadata

Metadata

Assignees

Labels

C-bugCategory: This is a bug.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions