Double Free Vulnerability in StackVec: Memory Corruption Risk
Summary
RUSTSEC-2026-0301: Double free in StackVec::retain when a predicate or element Drop panics. Affects stack_collections versions >= 0.3.0, < 0.3.3. Fixed in 0.3.3. How to fix ↓
Check if this vulnerability affects your application
Upload a manifest or SBOM and we'll show whether you're affected, plus every other risky package in the same scan.
No signup required · Results in about 60 seconds
Background
StackVec is a Rust library that provides a stack-allocated vector, allowing for efficient memory usage and performance. It is designed to handle collections of elements with a fixed capacity, making it suitable for scenarios where dynamic memory allocation is not desired. However, a recent vulnerability has been identified in the retain function, which can lead to memory corruption under specific conditions.
Vulnerability Detail
The vulnerability arises in the StackVec::retain method, where the new length of the vector is committed only after the internal loop has completed. If the predicate used for retaining elements or the destructor of a removed element panics during execution, the unwinding process leaves the length of the vector unchanged. This can result in a scenario where a previously removed element is revisited, leading to a double-drop situation. For types that own heap memory, this can cause a double-free, potentially leading to undefined behavior and security issues.
How To Fix
Latest published version: 0.3.3 as of 22 Oct 2026
The newest release already contains this fix.
Tip — Not sure which version your app runs? Vulert can match this fix to it. Scan free →
Workaround
If you cannot update the package immediately, consider avoiding the use of the retain function with types that implement Drop and may panic. Alternatively, you can implement your own version of the retain logic that safely handles panics.
Conclusion
The double free vulnerability in StackVec poses a significant risk for applications using this library with certain types. It is crucial to update to the patched version 0.3.3 to mitigate the risk of memory corruption and ensure application stability. Utilize tools like Vulert to monitor for vulnerabilities in your dependencies.
See every vulnerability recorded for stack_collections →
FAQ
The vulnerability can lead to memory corruption, double-free errors, and potential security risks in applications using StackVec with types that can panic during Drop.
You can use Vulert to monitor and alert for open-source vulnerabilities in your software. Check your Cargo.lock file at Vulert's playground without any signup.
Types that implement the Drop trait and can panic during their destructor are affected when used with the StackVec::retain method.
No, this vulnerability was introduced in version 0.3.0 and has been fixed in version 0.3.3.
If you cannot update, avoid using the retain function with potentially panicking types or implement a custom retain logic that handles panics safely.