diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2016-10-31 06:30:09 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2016-10-31 06:30:09 (GMT) |
commit | 04f17f103afcee73c65709252b0dba6411df7665 (patch) | |
tree | 9e4e1b95df17dc76aac9b3eb951a7785cc268607 /Modules/_lzmamodule.c | |
parent | 0bcd89b859dfbffd3cf8b2e7309998865deb9927 (diff) | |
download | cpython-04f17f103afcee73c65709252b0dba6411df7665.zip cpython-04f17f103afcee73c65709252b0dba6411df7665.tar.gz cpython-04f17f103afcee73c65709252b0dba6411df7665.tar.bz2 |
Issue #27517: LZMA compressor and decompressor no longer raise exceptions if
given empty data twice. Patch by Benjamin Fogle.
Diffstat (limited to 'Modules/_lzmamodule.c')
-rw-r--r-- | Modules/_lzmamodule.c | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/Modules/_lzmamodule.c b/Modules/_lzmamodule.c index 74c301d..e7b1ed9 100644 --- a/Modules/_lzmamodule.c +++ b/Modules/_lzmamodule.c @@ -527,6 +527,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; @@ -906,6 +908,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 |