maligned::align_first
causes incorrect deallocation
This review is from Crev, a distributed system for code reviews. To add your review, set up cargo-crev
.
0.2.1 (current) Thoroughness: None Understanding: None
by gitlab.com/KonradBorowski on 2022-04-08
Functions whose name starts with align_first
are unsound as they create
allocations whose alignment doesn't match the alignment of an allocation.
This can cause hard to debug issues when using alignment aware allocator.
Lib.rs has been able to verify that all files in the crate's tarball are in the crate's repository with a git tag matching the version. Please note that this check is still in beta, and absence of this confirmation does not mean that the files don't match.
Crates in the crates.io registry are tarball snapshots uploaded by crates' publishers. The registry is not using crates' git repositories, so there is a possibility that published crates have a misleading repository URL, or contain different code from the code in the repository.
To review the actual code of the crate, it's best to use cargo crev open maligned
. Alternatively, you can download the tarball of maligned v0.2.1 or view the source online.
maligned::align_first
manually allocates with an alignment larger than T, and then usesVec::from_raw_parts
on that allocation to get aVec<T>
.GlobalAlloc::dealloc
requires that thelayout
argument must be the same layout that was used to allocate that block of memory.When deallocating,
Box
andVec
may not respect the specified alignment and can cause undefined behavior.GHSA-wm8x-php5-hvq6