Issue #27517: LZMA compressor and decompressor no longer raise exceptions if

given empty data twice.  Patch by Benjamin Fogle.
This commit is contained in:
Serhiy Storchaka 2016-10-31 08:31:13 +02:00
commit 88b2219358
4 changed files with 47 additions and 0 deletions

View file

@ -521,6 +521,8 @@ compress(Compressor *c, uint8_t *data, size_t len, lzma_action action)
Py_BEGIN_ALLOW_THREADS
lzret = lzma_code(&c->lzs, action);
data_size = (char *)c->lzs.next_out - PyBytes_AS_STRING(result);
if (lzret == LZMA_BUF_ERROR && len == 0 && c->lzs.avail_out > 0)
lzret = LZMA_OK; /* That wasn't a real error */
Py_END_ALLOW_THREADS
if (catch_lzma_error(lzret))
goto error;
@ -896,6 +898,9 @@ 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