From 7a61ea527a2ed4657ba8c6b8e04360f5156dadd2 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..32864f8f 100644 --- a/src/ffi/c.rs +++ b/src/ffi/c.rs @@ -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), @@ -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),