
Cloud Vulnerability DB
A community-led vulnerabilities database
From<Cow<'_, [Item]>> for SmallVec<Item, INLINE, Global> adopts the pointer, length, and capacity of the Cow::Owned Vec, then returns. It does not stop that Vec from being dropped. The Vec frees the allocation and drops its elements before the returned SmallVec can be used or dropped. Ordinary use of the returned SmallVec can read freed memory; dropping it can free the same allocation again.
Affected source in the published tag: https://github.com/smallvec/smallvec/blob/v2.0.0-beta.5/src/conversions.rs#L333-L351
The existing From<Vec<Item>> for SmallVec<Item, INLINE> implementation handles ownership transfer and capacity invariants. Changing the owned arm to Cow::Owned(vector) => vector.into() made the saved test pass. This is a suggested direction, not a complete upstream fix review.
Add this as tests/cow_owned_transfer.rs to the unmodified v2.0.0-beta.5 source, then run cargo test --test cow_owned_transfer -- --nocapture. The test uses ManuallyDrop so it can observe the premature element drops without deliberately dropping the dangling returned vector on the failure path.
use smallvec::SmallVec;
use std::borrow::Cow;
use std::mem::ManuallyDrop;
use std::sync::{Arc, atomic::{AtomicUsize, Ordering}};
#[derive(Clone)]
struct Witness(Arc<AtomicUsize>);
impl Drop for Witness {
fn drop(&mut self) {
self.0.fetch_add(1, Ordering::SeqCst);
}
}
#[test]
fn owned_cow_transfers_elements_once() {
let drops = Arc::new(AtomicUsize::new(0));
let mut vec = Vec::with_capacity(8);
for _ in 0..3 {
vec.push(Witness(Arc::clone(&drops)));
}
let mut converted = ManuallyDrop::new(SmallVec::<Witness, 4>::from(Cow::Owned(vec)));
assert_eq!(drops.load(Ordering::SeqCst), 0, "Cow::Owned elements dropped during conversion");
unsafe { ManuallyDrop::drop(&mut converted) };
assert_eq!(drops.load(Ordering::SeqCst), 3);
}On the affected source, the saved run exited 101 and observed all three Witness destructors before the returned SmallVec was dropped. With the one-line ownership-transfer change, the same assertion passed.
Any safe caller converting an owned Cow<[T]> to SmallVec<T, N> can receive a dangling vector. This can cause memory corruption, a crash, or unintended reads when the value is used or dropped. The saved proof establishes premature destruction and the ownership error; it does not execute a second free or show a remote exploit. I found no public issue or advisory covering this conversion in a targeted search, but a private report may already exist.
Research credit: Aaron Elijah Mars of Aeon. Please credit both @aeonframework and @aaronjmars on publication.
Source: NVD
Free Vulnerability Assessment
Evaluate your cloud security practices across 9 security domains to benchmark your risk level and identify gaps in your defenses.
Get a personalized demo
"Best User Experience I have ever seen, provides full visibility to cloud workloads."
"Wiz provides a single pane of glass to see what is going on in our cloud environments."
"We know that if Wiz identifies something as critical, it actually is."