Skip to content

Commit 3395246

Browse files
ksj1230mbrubeck
authored andcommitted
Fix: SmallVec::leak() to panic on inline storage (GHSA-5h7v-3586-wm8c)
1 parent 5d76282 commit 3395246

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1682,6 +1682,9 @@ impl<T, const N: usize> SmallVec<T, N> {
16821682
}
16831683

16841684
pub fn leak<'a>(self) -> &'a mut [T] {
1685+
if !self.spilled() {
1686+
panic!("SmallVec::leak() called on inline (stack) SmallVec, which cannot be safely leaked");
1687+
}
16851688
let mut me = ManuallyDrop::new(self);
16861689
unsafe { core::slice::from_raw_parts_mut(me.as_mut_ptr(), me.len()) }
16871690
}

0 commit comments

Comments
 (0)