Skip to content

Commit

Permalink
Fix invalid write to uninitialized reserved Vec
Browse files Browse the repository at this point in the history
  • Loading branch information
rbran committed May 10, 2024
1 parent 2737b0d commit efbcaec
Showing 1 changed file with 5 additions and 20 deletions.
25 changes: 5 additions & 20 deletions rust/src/binaryview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,26 +237,11 @@ pub trait BinaryViewExt: BinaryViewBase {
/// Appends up to `len` bytes from address `offset` into `dest`
fn read_into_vec(&self, dest: &mut Vec<u8>, offset: u64, len: usize) -> usize {
let starting_len = dest.len();
let space = dest.capacity() - starting_len;

if space < len {
dest.reserve(len - space);
}

unsafe {
let res;

{
let dest_slice = dest.get_unchecked_mut(starting_len..starting_len + len);
res = self.read(dest_slice, offset);
}

if res > 0 {
dest.set_len(starting_len + res);
}

res
}
dest.resize(starting_len + len, 0);
let slice = &mut dest[starting_len..];
let read_size = self.read(slice, offset);
dest.truncate(starting_len + read_size);
read_size
}

fn notify_data_written(&self, offset: u64, len: usize) {
Expand Down

0 comments on commit efbcaec

Please sign in to comment.