Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
3. allow b"" as valid input data for decompress_buf()
  • Loading branch information
wjssz committed Jun 13, 2019
commit 454b278d6a671efe4cf340e81875f9f1a6b40816
4 changes: 2 additions & 2 deletions Lib/test/test_lzma.py
Original file line number Diff line number Diff line change
Expand Up @@ -1220,8 +1220,8 @@ def test_issue21872(self):
# simulate needs_input mechanism
# output internal state's 11 bytes
out2 = d2.decompress(b'')
self.assertEqual(len(out2), 0) # wrong behavior before fix
self.assertFalse(d2.eof) # wrong behavior before fix
self.assertEqual(len(out2), 11)
self.assertTrue(d2.eof)

Comment thread
This conversation was marked as resolved.

class OpenTestCase(unittest.TestCase):
Expand Down
6 changes: 3 additions & 3 deletions Modules/_lzmamodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -872,9 +872,6 @@ decompress_buf(Decompressor *d, Py_ssize_t max_length)
PyObject *result;
lzma_stream *lzs = &d->lzs;

if (lzs->avail_in == 0)
return PyBytes_FromStringAndSize(NULL, 0);

if (max_length < 0 || max_length >= INITIAL_BUFFER_SIZE)
result = PyBytes_FromStringAndSize(NULL, INITIAL_BUFFER_SIZE);
else
Expand All @@ -891,7 +888,10 @@ decompress_buf(Decompressor *d, Py_ssize_t max_length)
Py_BEGIN_ALLOW_THREADS
lzret = lzma_code(lzs, LZMA_RUN);
data_size = (char *)lzs->next_out - PyBytes_AS_STRING(result);
if (lzret == LZMA_BUF_ERROR && lzs->avail_in == 0 && lzs->avail_out > 0)
lzret = LZMA_OK; /* That wasn't a real error */
Py_END_ALLOW_THREADS

if (catch_lzma_error(lzret))
goto error;
if (lzret == LZMA_GET_CHECK || lzret == LZMA_NO_CHECK)
Expand Down