Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions src/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,11 @@ impl<W: Write + Send> DeflateEncoder<W> {
output
.try_reserve(bound - output.len())
.map_err(|e| io::Error::new(io::ErrorKind::Other, e))?;
output.resize(bound, 0);
// SAFETY: We just reserved sufficient capacity. The compressor writes to
// the buffer using `MaybeUninit` pointers, so uninitialized memory is fine.
unsafe {
output.set_len(bound);
}
}

let mode = if final_block {
Expand Down Expand Up @@ -101,7 +105,11 @@ impl<W: Write + Send> DeflateEncoder<W> {
output
.try_reserve(bound - output.len())
.map_err(|e| io::Error::new(io::ErrorKind::Other, e))?;
output.resize(bound, 0);
// SAFETY: We just reserved sufficient capacity. The compressor writes to
// the buffer using `MaybeUninit` pointers, so uninitialized memory is fine.
unsafe {
output.set_len(bound);
}
}

let mode = if final_block && i == num_chunks - 1 {
Expand Down Expand Up @@ -146,7 +154,11 @@ impl<W: Write + Send> DeflateEncoder<W> {
output
.try_reserve(bound - output.len())
.map_err(|e| io::Error::new(io::ErrorKind::Other, e))?;
output.resize(bound, 0);
// SAFETY: We just reserved sufficient capacity. The compressor writes to
// the buffer using `MaybeUninit` pointers, so uninitialized memory is fine.
unsafe {
output.set_len(bound);
}
}

let mode = if final_block {
Expand Down