Skip to content

Commit

Permalink
local_backend: don't reference uninitialized memory
Browse files Browse the repository at this point in the history
  • Loading branch information
Ralith committed Aug 8, 2023
1 parent fa75889 commit 75636d6
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions lib/src/local_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,19 +141,15 @@ impl Backend for LocalBackend {
let temp_file = NamedTempFile::new_in(&self.path).map_err(to_other_err)?;
let mut encoder = zstd::Encoder::new(temp_file.as_file(), 0).map_err(to_other_err)?;
let mut hasher = Blake2b512::new();
let mut buff: Vec<u8> = vec![0; 1 << 14];
loop {
let mut buff: Vec<u8> = Vec::with_capacity(1 << 14);
let bytes_read;
unsafe {
buff.set_len(1 << 14);
bytes_read = contents.read(&mut buff).map_err(to_other_err)?;
buff.set_len(bytes_read);
}
let bytes_read = contents.read(&mut buff).map_err(to_other_err)?;
if bytes_read == 0 {
break;
}
encoder.write_all(&buff).map_err(to_other_err)?;
hasher.update(&buff);
let bytes = &buff[..bytes_read];
encoder.write_all(bytes).map_err(to_other_err)?;
hasher.update(bytes);
}
encoder.finish().map_err(to_other_err)?;
let id = FileId::new(hasher.finalize().to_vec());
Expand Down

0 comments on commit 75636d6

Please sign in to comment.