{"id":"RUSTSEC-2026-0301","aliases":["RUSTSEC-2026-0301"],"related":[],"kind":"vulnerability","state":"published","title":"Double free in `StackVec::retain` when a predicate or element `Drop` panics","summary":"## Summary\n\n`StackVec::retain` committed its new length to `self.len` only after\nits internal loop completed. If the retain predicate or a removed\nelement's `Drop` implementation panicked before the loop finished,\nunwinding proceeded with `self.len` still equal to the original,\npre-retain length, leaving either a duplicated or already-destroyed\nelement inside `0..len`. `StackVec`'s own `Drop` then revisited that\nslot, causing a double-drop (and for heap-owning types, a double-free).\n\n## Impact\n\nAffects `StackVec<T, CAP>::retain` for `T: Drop` types where the\npredicate or the removed element's destructor can panic, on builds\nwith unwinding enabled (`panic = \"unwind\"`). `no_std`/`panic = \"abort\"`\nbuilds cannot trigger this, since unwinding never occurs.\n\n## Patch\n\nFixed in 0.3.3 using an unwind-safe backshift guard, matching the\napproach `alloc::vec::Vec::retain` uses.","summaryFormat":"markdown","summarySource":"rustsec","descriptions":[{"lang":"en","text":"## Summary\n\n`StackVec::retain` committed its new length to `self.len` only after\nits internal loop completed. If the retain predicate or a removed\nelement's `Drop` implementation panicked before the loop finished,\nunwinding proceeded with `self.len` still equal to the original,\npre-retain length, leaving either a duplicated or already-destroyed\nelement inside `0..len`. `StackVec`'s own `Drop` then revisited that\nslot, causing a double-drop (and for heap-owning types, a double-free).\n\n## Impact\n\nAffects `StackVec<T, CAP>::retain` for `T: Drop` types where the\npredicate or the removed element's destructor can panic, on builds\nwith unwinding enabled (`panic = \"unwind\"`). `no_std`/`panic = \"abort\"`\nbuilds cannot trigger this, since unwinding never occurs.\n\n## Patch\n\nFixed in 0.3.3 using an unwind-safe backshift guard, matching the\napproach `alloc::vec::Vec::retain` uses.","format":"markdown","source":"rustsec"}],"published":"2026-09-22T12:00:00.000Z","modified":"2026-09-22T21:00:02.870Z","severities":[],"cwes":[],"affected":[{"ranges":[{"type":"semver","introduced":"0.3.0","status":"affected","fixed":"0.3.3"}],"ecosystem":"crates.io","package":"stack_collections","purl":"pkg:cargo/stack_collections","source":"rustsec"}],"references":[{"url":"https://crates.io/crates/stack_collections","tags":["package"],"sources":["rustsec"]},{"url":"https://rustsec.org/advisories/RUSTSEC-2026-0301.html","tags":["advisory"],"sources":["rustsec"]},{"url":"https://github.com/OverwrittenCode/stack_collections/pull/4","tags":["web"],"sources":["rustsec"]}],"credits":[],"sources":[{"source":"rustsec","name":"RustSec Advisory Database","id":"RUSTSEC-2026-0301","url":"https://rustsec.org/advisories/RUSTSEC-2026-0301.html","licence":"CC0-1.0","modified":"2026-09-22T21:00:02.870Z"}],"updatedAt":"2026-11-25T22:56:43.412Z"}