Open ammaraskar opened 3 years ago
Heads up: this issue has been included in the RustSec advisory database. It will be surfaced by tools such as cargo-audit or cargo-deny from now on.
Once a fix is released to crates.io, please open a pull request to update the advisory with the patched version, or file an issue on the advisory database repository.
Hi there, we (Rust group @sslab-gatech) are scanning crates on crates.io for potential soundness bugs. We noticed a few panic safety issues in this library.
clone_from double-frees if T::clone panics
https://github.com/andrewhickman/id-map/blob/a2fa8d4a554dea2f9ea2ec6c3d06793576f8e7c0/src/lib.rs#L370-L380
The current values in the map are dropped and the
ids
are updated up front. This means that ifother.values.get_unchecked(id).clone()
panics, it can cause the previously dropped values to drop again.get_or_insert double frees if insertion function f panics
https://github.com/andrewhickman/id-map/blob/a2fa8d4a554dea2f9ea2ec6c3d06793576f8e7c0/src/lib.rs#L169-L180
Since this reserves space for the value before calling
ptr::write(space, f());
, iff
panics here, it can drop an already freed value.remove_set double frees if drop panics
https://github.com/andrewhickman/id-map/blob/a2fa8d4a554dea2f9ea2ec6c3d06793576f8e7c0/src/lib.rs#L192-L203
This code goes over to the ids to remove and calls
drop_in_place
on them. However if the drop function for the type panics, the element gets dropped again when theIdMap
is dropped.Code to recrate these problems is here: