fix(buffer): prevent possible buffer overflow in grow_zerofill

in `maybe_reserve` we have such code
    ```
        let new = self.buf.capacity() - self.buf.len();
        unsafe { grow_zerofill(&mut self.buf, new) }
    ```
    the original behavior of `grow_zerofill` in such case cause
    rewriting the memory behind the allocated vector.
This commit is contained in:
OlegTsyba
2016-03-02 17:20:18 +02:00
parent 63b2759e2f
commit c720295e99

View File

@@ -79,7 +79,7 @@ unsafe fn grow_zerofill(buf: &mut Vec<u8>, additional: usize) {
use std::ptr;
let len = buf.len();
buf.set_len(len + additional);
ptr::write_bytes(buf.as_mut_ptr().offset(len as isize), 0, buf.len());
ptr::write_bytes(buf.as_mut_ptr().offset(len as isize), 0, additional);
}
impl<R: Read> Read for BufReader<R> {