You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on May 24, 2024. It is now read-only.
Hi there, we (Rust group @sslab-gatech) are scanning crates on crates.io for potential soundness bugs. We noticed that in insert_slice_clone, it pushes elements over for insertion using ptr::copy here:
This can duplicate items in the Vec, after which it calls v.clone(), which can potentially panic. This means that during this panic the copied elements can be dropped twice. Here's a quick example of this issue:
#![forbid(unsafe_code)]use qwutils::*;// Type with a Clone() implementation that panics.structDropDetector(u32);implDropforDropDetector{fndrop(&mutself){println!("Dropping {}",self.0);}}implCloneforDropDetector{fnclone(&self) -> Self{panic!("DropDetector {} panic on clone()",self.0);}}fnmain(){letmut a = vec![DropDetector(1),DropDetector(2)];let b = [DropDetector(3)];
a.insert_slice_clone(0,&b);}
This outputs:
thread 'main' panicked at 'DropDetector 3 panic on clone()', src/main.rs:29:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Dropping 3
Dropping 1
Dropping 1
As you can see the first element is being dropped twice.
We'd recommend wrapping the vector in ManuallyDrop while you're operating on it to prevent this.
The text was updated successfully, but these errors were encountered:
Hi there, we (Rust group @sslab-gatech) are scanning crates on crates.io for potential soundness bugs. We noticed that in
insert_slice_clone
, it pushes elements over for insertion using ptr::copy here:rust_utils/src/imp/vec.rs
Lines 83 to 92 in f4eae5b
This can duplicate items in the
Vec
, after which it callsv.clone()
, which can potentially panic. This means that during this panic the copied elements can be dropped twice. Here's a quick example of this issue:This outputs:
As you can see the first element is being dropped twice.
We'd recommend wrapping the vector in
ManuallyDrop
while you're operating on it to prevent this.The text was updated successfully, but these errors were encountered: