Skip to content

Commit 84e506a

Browse files
committed
Fix incomplete stream
1 parent 1de80c0 commit 84e506a

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/isal/isal_zlib.pyx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ cpdef decompress(data,
199199

200200
# Implementation imitated from CPython's zlibmodule.c
201201
try:
202-
while ibuflen != 0 or stream.block_state != ISAL_BLOCK_FINISH:
202+
while ibuflen != 0 and stream.block_state != ISAL_BLOCK_FINISH:
203203
ibuflen = Py_ssize_t_min(remains, max_input_buffer)
204204
ibuf = data[position: position + ibuflen]
205205
position += ibuflen
@@ -225,6 +225,8 @@ cpdef decompress(data,
225225
out.append(obuf[:obuflen - stream.avail_out])
226226
if stream.avail_in == 0:
227227
break
228+
if stream.block_state != ISAL_BLOCK_FINISH:
229+
raise IsalError("incomplete or truncated stream")
228230
return b"".join(out)
229231
finally:
230232
PyMem_Free(obuf)

tests/test_zlib_compliance.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ def test_incomplete_stream(self):
207207
# A useful error message is given
208208
x = isal_zlib.compress(HAMLET_SCENE)
209209
self.assertRaisesRegex(isal_zlib.error,
210-
"Error -5 while decompressing data: incomplete or truncated stream",
210+
"incomplete or truncated stream",
211211
isal_zlib.decompress, x[:-1])
212212

213213
# Memory use of the following functions takes into account overallocation

0 commit comments

Comments
 (0)