@@ -152,14 +152,12 @@ cdef arrange_output_buffer_with_maximum(stream_or_state *stream,
152
152
new_length = length << 1
153
153
else :
154
154
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)
156
156
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" )
160
158
buffer [0 ] = new_buffer
161
159
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)
163
161
stream.next_out = buffer [0 ] + occupied
164
162
return length
165
163
@@ -171,7 +169,7 @@ cdef arrange_output_buffer(stream_or_state *stream, unsigned char **buffer, Py_s
171
169
return ret
172
170
173
171
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)
175
173
remains[0 ] -= stream.avail_in
176
174
177
175
def compress (data ,
@@ -616,8 +614,8 @@ cdef class Decompress:
616
614
# Initialise output buffer
617
615
cdef unsigned char * obuf = NULL
618
616
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
621
619
622
620
try :
623
621
# This loop reads all the input bytes. If there are no input bytes
@@ -636,7 +634,7 @@ cdef class Decompress:
636
634
# Are raised. So we remain in pure C code if we check for
637
635
# COMP_OK first.
638
636
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 :
640
638
break
641
639
if self .stream.block_state == ISAL_BLOCK_FINISH or ibuflen == 0 or max_length_reached:
642
640
break
@@ -667,6 +665,8 @@ cdef class Decompress:
667
665
cdef unsigned int obuflen = length
668
666
cdef unsigned char * obuf = NULL
669
667
668
+ cdef int err
669
+
670
670
try :
671
671
while True :
672
672
arrange_input_buffer(& self .stream, & ibuflen)
@@ -681,7 +681,7 @@ cdef class Decompress:
681
681
# Instead of output buffer resizing as the zlibmodule.c example
682
682
# the data is appended to a list.
683
683
# 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 :
685
685
break
686
686
if self .stream.block_state == ISAL_BLOCK_FINISH or ibuflen == 0 :
687
687
break
0 commit comments