Skip to content

Commit 0307ba8

Browse files
committed
Fix decompress
1 parent 4b5f794 commit 0307ba8

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/isal/isal_zlib.pyx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -152,14 +152,12 @@ cdef arrange_output_buffer_with_maximum(stream_or_state *stream,
152152
new_length = length << 1
153153
else:
154154
new_length = max_length
155-
new_buffer = <unsigned char *>PyMem_Realloc(buffer[0], new_length + 1)
155+
new_buffer = <unsigned char *>PyMem_Realloc(buffer[0], new_length)
156156
if new_buffer == NULL:
157-
new_buffer = <unsigned char*>PyMem_Malloc(new_length * sizeof(char))
158-
if new_buffer == NULL:
159-
raise MemoryError("Unssufficient memory for buffer allocation")
157+
raise MemoryError("Unssufficient memory for buffer allocation")
160158
buffer[0] = new_buffer
161159
length = new_length
162-
stream.avail_out = py_ssize_t_min(length - occupied, UINT32_MAX)
160+
stream.avail_out = <unsigned int>py_ssize_t_min(length - occupied, UINT32_MAX)
163161
stream.next_out = buffer[0] + occupied
164162
return length
165163

@@ -171,7 +169,7 @@ cdef arrange_output_buffer(stream_or_state *stream, unsigned char **buffer, Py_s
171169
return ret
172170

173171
cdef void arrange_input_buffer(stream_or_state *stream, Py_ssize_t *remains):
174-
stream.avail_in = py_ssize_t_min(remains[0], UINT32_MAX)
172+
stream.avail_in = <unsigned int>py_ssize_t_min(remains[0], UINT32_MAX)
175173
remains[0] -= stream.avail_in
176174

177175
def compress(data,
@@ -616,8 +614,8 @@ cdef class Decompress:
616614
# Initialise output buffer
617615
cdef unsigned char *obuf = NULL
618616
cdef Py_ssize_t obuflen = DEF_BUF_SIZE
619-
if obuflen > max_length:
620-
obuflen = max_length
617+
if obuflen > hard_limit:
618+
obuflen = hard_limit
621619

622620
try:
623621
# This loop reads all the input bytes. If there are no input bytes
@@ -636,7 +634,7 @@ cdef class Decompress:
636634
# Are raised. So we remain in pure C code if we check for
637635
# COMP_OK first.
638636
check_isal_inflate_rc(err)
639-
if self.stream.avail_out != 0:
637+
if self.stream.block_state == ISAL_BLOCK_FINISH or self.stream.avail_out != 0:
640638
break
641639
if self.stream.block_state == ISAL_BLOCK_FINISH or ibuflen ==0 or max_length_reached:
642640
break
@@ -667,6 +665,8 @@ cdef class Decompress:
667665
cdef unsigned int obuflen = length
668666
cdef unsigned char * obuf = NULL
669667

668+
cdef int err
669+
670670
try:
671671
while True:
672672
arrange_input_buffer(&self.stream, &ibuflen)
@@ -681,7 +681,7 @@ cdef class Decompress:
681681
# Instead of output buffer resizing as the zlibmodule.c example
682682
# the data is appended to a list.
683683
# TODO: Improve this with the buffer protocol.
684-
if self.stream.avail_out != 0:
684+
if self.stream.avail_out != 0 or self.stream.block_state == ISAL_BLOCK_FINISH:
685685
break
686686
if self.stream.block_state == ISAL_BLOCK_FINISH or ibuflen == 0:
687687
break

0 commit comments

Comments
 (0)