Skip to content

Commit 39272f1

Browse files
committed
Fix infinite loop issue
1 parent 994d40b commit 39272f1

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/isal/isal_zlib.pyx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,7 @@ cdef class Decompress:
410410
cdef unsigned long prev_avail_out
411411
cdef unsigned long bytes_written
412412
cdef int err
413+
cdef bint last_round = 0
413414
# This loop reads all the input bytes. If there are no input bytes
414415
# anymore the output is written.
415416
while (self.stream.avail_out == 0
@@ -420,6 +421,9 @@ cdef class Decompress:
420421
break
421422
elif total_bytes + self.obuflen >= max_length:
422423
self.stream.avail_out = max_length - total_bytes
424+
# The inflate process may not fill all available bytes so
425+
# we make sure this is the last round.
426+
last_round = 1
423427
else:
424428
self.stream.avail_out = self.obuflen
425429
prev_avail_out = self.stream.avail_out
@@ -432,7 +436,7 @@ cdef class Decompress:
432436
bytes_written = prev_avail_out - self.stream.avail_out
433437
total_bytes += bytes_written
434438
out.append(self.obuf[:bytes_written])
435-
if self.stream.block_state == ISAL_BLOCK_FINISH:
439+
if self.stream.block_state == ISAL_BLOCK_FINISH or last_round:
436440
break
437441
# Save unconsumed input implementation from zlibmodule.c
438442
if self.stream.block_state == ISAL_BLOCK_FINISH:

0 commit comments

Comments
 (0)