Skip to content

Commit

Permalink
Fix invalid write to uninitialized Vec
Browse files Browse the repository at this point in the history
  • Loading branch information
rbran committed May 10, 2024
1 parent 7294b9b commit 3df2733
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions rust/src/binaryview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,18 +225,11 @@ pub trait BinaryViewExt: BinaryViewBase {

/// Reads up to `len` bytes from address `offset`
fn read_vec(&self, offset: u64, len: usize) -> Vec<u8> {
let mut ret = Vec::with_capacity(len);
let mut ret = vec![0; len];

unsafe {
let res;

{
let dest_slice = ret.get_unchecked_mut(0..len);
res = self.read(dest_slice, offset);
}

ret.set_len(res);
}
let slice = ret.get_mut(0..len).unwrap();
let size = self.read(slice, offset);
ret.truncate(size);

ret
}
Expand Down

0 comments on commit 3df2733

Please sign in to comment.