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
Hi there, we (Rust group @sslab-gatech) are scanning crates on crates.io for potential soundness bugs. We noticed that in Window::new, the bytes read returned from the reader are used to set_len:
let size = try!(reader.read(front.as_mut_slice()));
unsafe{
front.set_len(size);
}
let size = try!(reader.read(back.as_mut_slice()));
unsafe{
back.set_len(size);
}
This means that a buggy Read implementation that returns more bytes than the buf size can cause front and back to contain initialized memory. See this example:
#![forbid(unsafe_code)]use rdiff::BlockHashes;use std::io::{Cursor,Read};structMyRead{first:bool,}implMyRead{pubfnnew() -> Self{MyRead{first:false}}}implReadforMyRead{fnread(&mutself,_buf:&mut[u8]) -> std::io::Result<usize>{if !self.first{self.first = true;// First iteration: return more than the buffer sizeOk(256)}else{// Second iteration: indicate that we are doneOk(0)}}}fnmain(){letmut hashes = BlockHashes::new(Cursor::new("Hello"),32).unwrap();let diff = hashes.diff_and_update(MyRead::new()).unwrap();for insert in diff.inserts(){println!("{:?}", insert);}}
This outputs:
Insert(0, '1���� =�>�U��X���������������X�q')
I think there should be an assert in Window::new to ensure that the number of bytes are <= block_size
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
Window::new
, the bytes read returned from thereader
are used toset_len
:rdiff/src/window.rs
Lines 9 to 18 in 6680843
This means that a buggy
Read
implementation that returns more bytes than the buf size can causefront
andback
to contain initialized memory. See this example:This outputs:
I think there should be an assert in
Window::new
to ensure that the number of bytes are<= block_size
The text was updated successfully, but these errors were encountered: