Skip to content

Commit

Permalink
Patched an infinite loop bug in src/mem.rs, impl Decompress::decompre…
Browse files Browse the repository at this point in the history
…ss() (#86)

* Solved infinite loop problem when output.length() is 0x1_0000_0000 exactly

* Fixed incomplete and too complicated patch
  • Loading branch information
bjrjk authored Jan 5, 2023
1 parent 016e181 commit 90c9c18
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,9 @@ impl Compress {
return Ok(Status::RunOk);
}
self.inner.raw.next_in = input.as_ptr() as *mut _;
self.inner.raw.avail_in = input.len() as c_uint;
self.inner.raw.avail_in = input.len().min(c_uint::MAX as usize) as c_uint;
self.inner.raw.next_out = output.as_mut_ptr() as *mut _;
self.inner.raw.avail_out = output.len() as c_uint;
self.inner.raw.avail_out = output.len().min(c_uint::MAX as usize) as c_uint;
unsafe {
match ffi::BZ2_bzCompress(&mut *self.inner.raw, action as c_int) {
ffi::BZ_RUN_OK => Ok(Status::RunOk),
Expand Down Expand Up @@ -225,9 +225,9 @@ impl Decompress {
/// Decompress a block of input into a block of output.
pub fn decompress(&mut self, input: &[u8], output: &mut [u8]) -> Result<Status, Error> {
self.inner.raw.next_in = input.as_ptr() as *mut _;
self.inner.raw.avail_in = input.len() as c_uint;
self.inner.raw.avail_in = input.len().min(c_uint::MAX as usize) as c_uint;
self.inner.raw.next_out = output.as_mut_ptr() as *mut _;
self.inner.raw.avail_out = output.len() as c_uint;
self.inner.raw.avail_out = output.len().min(c_uint::MAX as usize) as c_uint;
unsafe {
match ffi::BZ2_bzDecompress(&mut *self.inner.raw) {
ffi::BZ_OK => Ok(Status::Ok),
Expand Down

0 comments on commit 90c9c18

Please # to comment.