Skip to content

Commit

Permalink
Merge pull request #380 from Manishearth/reset-stream
Browse files Browse the repository at this point in the history
Reset StreamWrapper after calling mz_inflate / mz_deflate
  • Loading branch information
Byron committed Oct 13, 2023
2 parents f62ff42 + 7a61ea5 commit 223f829
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/ffi/c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,12 @@ impl InflateBackend for Inflate {
self.inner.total_in += (raw.next_in as usize - input.as_ptr() as usize) as u64;
self.inner.total_out += (raw.next_out as usize - output.as_ptr() as usize) as u64;

// reset these pointers so we don't accidentally read them later
raw.next_in = ptr::null_mut();
raw.avail_in = 0;
raw.next_out = ptr::null_mut();
raw.avail_out = 0;

match rc {
MZ_DATA_ERROR | MZ_STREAM_ERROR => mem::decompress_failed(self.inner.msg()),
MZ_OK => Ok(Status::Ok),
Expand Down Expand Up @@ -314,6 +320,12 @@ impl DeflateBackend for Deflate {
self.inner.total_in += (raw.next_in as usize - input.as_ptr() as usize) as u64;
self.inner.total_out += (raw.next_out as usize - output.as_ptr() as usize) as u64;

// reset these pointers so we don't accidentally read them later
raw.next_in = ptr::null_mut();
raw.avail_in = 0;
raw.next_out = ptr::null_mut();
raw.avail_out = 0;

match rc {
MZ_OK => Ok(Status::Ok),
MZ_BUF_ERROR => Ok(Status::BufError),
Expand Down

0 comments on commit 223f829

Please sign in to comment.