From 5314cf19d08a0fa644f0895f39b8d5e9bf0f9962 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Thu, 12 Oct 2023 09:19:33 -0700 Subject: [PATCH] Reset StreamWrapper after calling mz_inflate / mz_deflate --- src/ffi/c.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/ffi/c.rs b/src/ffi/c.rs index 48acd438..75428c52 100644 --- a/src/ffi/c.rs +++ b/src/ffi/c.rs @@ -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; @@ -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;