Geal / cargo-real-deps

Cargo subcommand to check which crates are built depending on features
5 stars 3 forks source link

Undefined behavior: attempted to zero-initialize type ... which is invalid #4

Open dtolnay opened 3 years ago

dtolnay commented 3 years ago

Cargo-real-deps appears to immediately panic if built by a recent version of rustc.

$ cargo-real-deps --path Cargo.toml 
thread 'main' panicked at 'attempted to zero-initialize type `sized_chunks::sized_chunk::Chunk<(core::package_id::PackageId, im_rc::OrdMap<core::package_id::PackageId, std::rc::Rc<std::vec::Vec<core::dependency::Dependency>>>)>`, which is invalid', /home/david/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/mem/mod.rs:623:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Alvenix commented 3 years ago

After short investigations as I encountered the problem in cargo bitbake which use cargo as dependency too.

I believe the problem is rooted at sized_chunks version 0.3.1 dependency. In 0.3.2 the change log included the following: "Replaced ManuallyDrop in implementations with MaybeUninit, along with a general unsafe code cleanup". However, the version was yanked because it increase the minimum supported rustc version and was released under 0.4.0.

Enforcing the newer version fix the problem.