CVE-2026-6654: thin-vec Use-After-Free And Double Free Vulnerability
HIGHCVE-2026-6654 is a HIGH (CVSS 7.3) use-after-free and double free vulnerability (CWE-415: Double Free) affecting thin-vec libraries in the crates.io ecosystem. The issue involves use-after-free and double free in intoiter::drop when element drop panics. Remediation is available by upgrading affected packages to version 0.2.16.
CVE-2026-6654 at a Glance
Security Impact
CVSS: 7.3
The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:L/AC:L/PR:N/UI:N/S:U/C:L/I:L/A:H).
How to Fix CVE-2026-6654
To remediate this vulnerability, upgrade all affected thin-vec dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.
Upgrade thin-vec to 0.2.16
Run the following command in your project directory to verify that all resolved dependencies use the patched release:
inspect dependencies for thin-vec
How to Check if You Are Affected
To determine whether your application is affected by CVE-2026-6654, inspect your project dependencies for thin-vec:
inspect dependencies for thin-vec
Analyze the terminal output to locate any version of thin-vec in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 0.2.16), your application is affected.
Note: Verify declared build manifests and deployed runtime container environments.
Technical Details
Vulnerability Mechanism & Technical Analysis
This vulnerability is classified under CWE-415: Double Free, where the product calls free() twice on the same memory address. In thin-vec, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.
Source Advisory Statement
CVE-2026-6654 Affected thin-vec Versions
1 component(s)| Product / Package | Ecosystem | Affected Versions | Fixed Version |
|---|---|---|---|
|
thin-vec
|
crates.io |
< 0.2.16
|
0.2.16
|
References
Frequently Asked Questions
What is CVE-2026-6654?
Which thin-vec versions are affected?
What version fixes CVE-2026-6654?
Is thin-vec affected?
What is the CVSS score of CVE-2026-6654?
What CWE is associated with CVE-2026-6654?
How can I check crates.io dependencies for CVE-2026-6654?
Machine-readable OSV JSON
OSV v1.5 Schema
{
"schema_version" : "1.4.0",
"id" : "GHSA-xphw-cqx3-667j",
"modified" : "2026-05-05T15:43:14Z",
"published" : "2026-04-15T19:24:54Z",
"aliases" : [ "CVE-2026-6654" ],
"summary" : "thin-vec: Use-After-Free and Double Free in IntoIter::drop When Element Drop Panics",
"details" : "### Summary\n\nA **Double Free / Use-After-Free (UAF)** vulnerability has been identified in the `IntoIter::drop` and `ThinVec::clear` implementations of the `thin_vec` crate.\nBoth vulnerabilities share the same root cause and can trigger memory corruption using only safe Rust code — no `unsafe` blocks required.\nUndefined Behavior has been confirmed via **Miri** and **AddressSanitizer (ASAN)**.\n\n---\n\n### Details\n\nBoth vulnerabilities share the same root cause. When a **panic occurs** during sequential element deallocation, the subsequent length cleanup code (`set_len(0)`) is never executed. During stack unwinding, the container is dropped again, causing already-freed memory to be re-freed (Double Free / UAF).\n\n#### Vulnerability 1 — `IntoIter::drop`\n\n**Location:** `thin-vec/src/lib.rs` L.2308~2314\n\n`IntoIter::drop` transfers ownership of the internal buffer via `mem::replace`, then sequentially frees elements via `ptr::drop_in_place`.\nIf a panic occurs during element deallocation, `set_len_non_singleton(0)` is never reached. During unwinding, `vec` is dropped again, re-freeing already-freed elements.\nThe standard library's `std::vec::IntoIter` prevents this with a **DropGuard pattern**, but thin-vec lacks this defense.\n\n```rust\n// Problematic structure (conceptual representation)\nimpl<T> Drop for IntoIter<T> {\n fn drop(&mut self) {\n let mut vec = mem::replace(&mut self.vec, ThinVec::new());\n unsafe {\n ptr::drop_in_place(vec.remaining_slice_mut()); // ← panic may occur here\n vec.set_len_non_singleton(0); // ← unreachable on panic\n }\n // During unwinding, vec is dropped again → Double Free\n }\n}\n```\n\n#### Vulnerability 2 — `ThinVec::clear`\n\n`clear()` calls `ptr::drop_in_place(&mut self[..])` followed by `self.set_len(0)` to reset the length.\nIf a panic occurs during element deallocation, `set_len(0)` is never executed. When the `ThinVec` itself is subsequently dropped, already-freed elements are freed again.\n\n```rust\n// Problematic structure (conceptual representation)\npub fn clear(&mut self) {\n unsafe {\n ptr::drop_in_place(&mut self[..]); // ← panic may occur here\n self.set_len(0); // ← unreachable on panic\n }\n // ThinVec drop later → Double Free\n}\n```\n\n#### Recommended Fix\n\nBoth vulnerabilities can be resolved with the same pattern:\n\n- **DropGuard pattern:** Insert an RAII guard before `drop_in_place` to guarantee `set_len(0)` is called regardless of panic\n- **Pre-zeroing approach:** Set the length to 0 before calling `drop_in_place`\n\n---\n\n### PoC\n\n**Requirements:** Rust nightly toolchain, `thin-vec = \"0.2.14\"`\n\n```bash\n# Miri\ncargo +nightly miri run\n\n# ASAN\nRUSTFLAGS=\"-Z sanitizer=address\" cargo +nightly run --release\n```\n\n#### PoC-1: `IntoIter::drop`\n\n```rust\nuse thin_vec::ThinVec;\n\nstruct PanicBomb(String);\n\nimpl Drop for PanicBomb {\n fn drop(&mut self) {\n if self.0 == \"panic\" {\n panic!(\"panic!\");\n }\n println!(\"Dropping: {}\", self.0);\n }\n}\n\nfn main() {\n let mut v = ThinVec::new();\n v.push(PanicBomb(String::from(\"normal1\")));\n v.push(PanicBomb(String::from(\"panic\"))); // trigger element\n v.push(PanicBomb(String::from(\"normal2\")));\n\n let mut iter = v.into_iter();\n iter.next();\n // When iter is dropped: panic occurs at \"panic\" element\n // → During unwinding, Double Drop is triggered on \"normal1\" (already freed)\n}\n```\n\n**Miri output:**\n```\nerror: Undefined Behavior: pointer not dereferenceable:\n alloc227 has been freed, so this pointer is dangling\n\nstack backtrace:\n 3: <PanicBomb as Drop>::drop ← Double Drop entry\n 6: <ThinVec<T> as Drop>::drop::drop_non_singleton\n 9: <IntoIter<T> as Drop>::drop::drop_non_singleton ← lib.rs:2310 (root cause)\n```\n\n**ASAN output:**\n```\n==66150==ERROR: AddressSanitizer: heap-use-after-free on address 0x7afa685e0010\nREAD of size 7 at 0x7afa685e0010\n #0 memcpy\n #4 drop_in_place::<PanicBomb> ← Double Drop entry point\n #5 <ThinVec as Drop>::drop::drop_non_singleton\n #6 <IntoIter as Drop>::drop::drop_non_singleton\n```\n\n#### PoC-2: `ThinVec::clear`\n\n```rust\nuse thin_vec::ThinVec;\nuse std::panic;\n\nstruct Poison(Box<usize>, &'static str);\n\nimpl Drop for Poison {\n fn drop(&mut self) {\n if self.1 == \"panic\" {\n panic!(\"panic!\");\n }\n println!(\"Dropping: {}\", self.0);\n }\n}\n\nfn main() {\n let mut v = ThinVec::new();\n v.push(Poison(Box::new(1), \"normal1\")); // index 0\n v.push(Poison(Box::new(2), \"panic\")); // index 1 → panic triggered here\n v.push(Poison(Box::new(3), \"normal2\")); // index 2\n\n let _ = panic::catch_unwind(panic::AssertUnwindSafe(|| {\n v.clear();\n // panic occurs at \"panic\" element during clear()\n // → set_len(0) is never called\n // → already-freed elements are re-freed when v goes out of scope\n }));\n}\n```\n\n---\n\n### Impact\n\n**Vulnerability classification:**\n- CWE-415: Double Free\n- CWE-416: Use-After-Free\n\n**Affected code:** All code satisfying the following conditions simultaneously:\n\n1. `ThinVec` stores heap-owning types (`String`, `Vec`, `Box`, etc.)\n2. (Vulnerability 1) An iterator is created via `into_iter()` and dropped before being fully consumed, or\n (Vulnerability 2) `clear()` is called while a remaining element's `Drop` implementation can panic\n3. The `Drop` implementation of a remaining element triggers a panic\n\nAdditionally, when combined with `Box<dyn Trait>` types, an exploit primitive enabling Arbitrary Code Execution (ACE) via heap spray and vtable hijacking has been confirmed. If the freed fat pointer slot (16 bytes) at the point of Double Drop is reclaimed by an attacker-controlled fake vtable, subsequent Drop calls can be redirected to attacker-controlled code.",
"severity" : [ {
"type" : "CVSS_V3",
"score" : "CVSS:3.1/AV:L/AC:L/PR:N/UI:N/S:U/C:L/I:L/A:H"
} ],
"affected" : [ {
"package" : {
"ecosystem" : "crates.io",
"name" : "thin-vec"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "0"
}, {
"fixed" : "0.2.16"
} ]
} ]
} ],
"references" : [ {
"type" : "WEB",
"url" : "https://github.com/mozilla/thin-vec/security/advisories/GHSA-xphw-cqx3-667j"
}, {
"type" : "ADVISORY",
"url" : "https://nvd.nist.gov/vuln/detail/CVE-2026-6654"
}, {
"type" : "PACKAGE",
"url" : "https://github.com/mozilla/thin-vec"
}, {
"type" : "WEB",
"url" : "https://rustsec.org/advisories/RUSTSEC-2026-0103.html"
} ],
"database_specific" : {
"cwe_ids" : [ "CWE-415", "CWE-416" ],
"severity" : "HIGH",
"github_reviewed" : true,
"github_reviewed_at" : "2026-04-15T19:24:54Z",
"nvd_published_at" : "2026-04-20T11:16:19Z"
}
}