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 5314cf1
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 @@ -221,6 +221,12 @@ impl InflateBackend for Inflate {

let rc = unsafe { mz_inflate(raw, flush as c_int) };

// 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;

// Unfortunately the total counters provided by zlib might be only
// 32 bits wide and overflow while processing large amounts of data.
self.inner.total_in += (raw.next_in as usize - input.as_ptr() as usize) as u64;
Expand Down Expand Up @@ -309,6 +315,12 @@ impl DeflateBackend for Deflate {

let rc = unsafe { mz_deflate(raw, flush as c_int) };

// 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;

// Unfortunately the total counters provided by zlib might be only
// 32 bits wide and overflow while processing large amounts of data.
self.inner.total_in += (raw.next_in as usize - input.as_ptr() as usize) as u64;
Expand Down

0 comments on commit 5314cf1

Please sign in to comment.