Skip to content

Commit f966514

Browse files
committed
Correct unconsumed input
1 parent 68194c6 commit f966514

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

src/isal/isal_zlib.pyx

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -556,18 +556,23 @@ cdef class Decompress:
556556
cdef save_unconsumed_input(self, Py_buffer *data):
557557
cdef Py_ssize_t old_size, new_size, left_size
558558
cdef bytes new_data
559-
if self.stream.avail_in > 0:
560-
left_size = <unsigned char*>data.buf + data.len - self.stream.next_in
561-
new_data = PyBytes_FromStringAndSize(<char *>self.stream.next_in, left_size)
562-
else:
563-
new_data = b""
564559
if self.stream.block_state == ISAL_BLOCK_FINISH:
565560
self.eof = 1
566-
# The block is finished and this decompressobject can not be
567-
# used anymore. Some unused data is in the bitbuffer and has to
568-
# be recovered.
569-
self.unused_data = self._view_bitbuffer() + new_data
570-
else:
561+
if self.stream.avail_in > 0:
562+
left_size = <unsigned char*>data.buf + data.len - self.stream.next_in
563+
new_data = PyBytes_FromStringAndSize(<char *>self.stream.next_in, left_size)
564+
else:
565+
new_data = b""
566+
if not self.unused_data:
567+
# The block is finished and this decompressobject can not be
568+
# used anymore. Some unused data is in the bitbuffer and has to
569+
# be recovered. Only when self.unused_data is empty. Otherwise
570+
# we assume the bitbuffer data is already added.
571+
self.unused_data = self._view_bitbuffer()
572+
self.unused_data += new_data
573+
elif self.stream.avail_in > 0 or self.unconsumed_tail:
574+
left_size = <unsigned char*>data.buf + data.len - self.stream.next_in
575+
new_data = PyBytes_FromStringAndSize(<char *>self.stream.next_in, left_size)
571576
self.unconsumed_tail = new_data
572577

573578
def decompress(self, data, Py_ssize_t max_length = 0):

0 commit comments

Comments
 (0)