Skip to content

Commit

Permalink
Reset StreamWrapper after calling mz_inflate / mz_deflate
Browse files Browse the repository at this point in the history
  • Loading branch information
Manishearth committed Oct 12, 2023
1 parent f62ff42 commit 7a61ea5
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 7a61ea5

Please sign in to comment.