Skip to content

Commit 90c9c18

Browse files
authored
Patched an infinite loop bug in src/mem.rs, impl Decompress::decompress() (#86)
* Solved infinite loop problem when output.length() is 0x1_0000_0000 exactly * Fixed incomplete and too complicated patch
1 parent 016e181 commit 90c9c18

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/mem.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,9 @@ impl Compress {
150150
return Ok(Status::RunOk);
151151
}
152152
self.inner.raw.next_in = input.as_ptr() as *mut _;
153-
self.inner.raw.avail_in = input.len() as c_uint;
153+
self.inner.raw.avail_in = input.len().min(c_uint::MAX as usize) as c_uint;
154154
self.inner.raw.next_out = output.as_mut_ptr() as *mut _;
155-
self.inner.raw.avail_out = output.len() as c_uint;
155+
self.inner.raw.avail_out = output.len().min(c_uint::MAX as usize) as c_uint;
156156
unsafe {
157157
match ffi::BZ2_bzCompress(&mut *self.inner.raw, action as c_int) {
158158
ffi::BZ_RUN_OK => Ok(Status::RunOk),
@@ -225,9 +225,9 @@ impl Decompress {
225225
/// Decompress a block of input into a block of output.
226226
pub fn decompress(&mut self, input: &[u8], output: &mut [u8]) -> Result<Status, Error> {
227227
self.inner.raw.next_in = input.as_ptr() as *mut _;
228-
self.inner.raw.avail_in = input.len() as c_uint;
228+
self.inner.raw.avail_in = input.len().min(c_uint::MAX as usize) as c_uint;
229229
self.inner.raw.next_out = output.as_mut_ptr() as *mut _;
230-
self.inner.raw.avail_out = output.len() as c_uint;
230+
self.inner.raw.avail_out = output.len().min(c_uint::MAX as usize) as c_uint;
231231
unsafe {
232232
match ffi::BZ2_bzDecompress(&mut *self.inner.raw) {
233233
ffi::BZ_OK => Ok(Status::Ok),

0 commit comments

Comments
 (0)