diff options
Diffstat (limited to 'Modules/bz2module.c')
-rw-r--r-- | Modules/bz2module.c | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/Modules/bz2module.c b/Modules/bz2module.c index 9b39442..a40334d 100644 --- a/Modules/bz2module.c +++ b/Modules/bz2module.c @@ -1553,6 +1553,8 @@ BZ2Comp_compress(BZ2CompObject *self, PyObject *args) Util_CatchBZ2Error(bzerror); goto error; } + if (bzs->avail_in == 0) + break; /* no more input data */ if (bzs->avail_out == 0) { bufsize = Util_NewBufferSize(bufsize); if (_PyString_Resize(&ret, bufsize) < 0) { @@ -1562,8 +1564,6 @@ BZ2Comp_compress(BZ2CompObject *self, PyObject *args) bzs->next_out = BUF(ret) + (BZS_TOTAL_OUT(bzs) - totalout); bzs->avail_out = bufsize - (bzs->next_out - BUF(ret)); - } else if (bzs->avail_in == 0) { - break; } } @@ -1845,6 +1845,8 @@ BZ2Decomp_decompress(BZ2DecompObject *self, PyObject *args) Util_CatchBZ2Error(bzerror); goto error; } + if (bzs->avail_in == 0) + break; /* no more input data */ if (bzs->avail_out == 0) { bufsize = Util_NewBufferSize(bufsize); if (_PyString_Resize(&ret, bufsize) < 0) { @@ -1855,8 +1857,6 @@ BZ2Decomp_decompress(BZ2DecompObject *self, PyObject *args) bzs->next_out = BUF(ret) + (BZS_TOTAL_OUT(bzs) - totalout); bzs->avail_out = bufsize - (bzs->next_out - BUF(ret)); - } else if (bzs->avail_in == 0) { - break; } } @@ -2134,6 +2134,13 @@ bz2_decompress(PyObject *self, PyObject *args) Py_DECREF(ret); return NULL; } + if (bzs->avail_in == 0) { + BZ2_bzDecompressEnd(bzs); + PyErr_SetString(PyExc_ValueError, + "couldn't find end of stream"); + Py_DECREF(ret); + return NULL; + } if (bzs->avail_out == 0) { bufsize = Util_NewBufferSize(bufsize); if (_PyString_Resize(&ret, bufsize) < 0) { @@ -2143,12 +2150,6 @@ bz2_decompress(PyObject *self, PyObject *args) } bzs->next_out = BUF(ret) + BZS_TOTAL_OUT(bzs); bzs->avail_out = bufsize - (bzs->next_out - BUF(ret)); - } else if (bzs->avail_in == 0) { - BZ2_bzDecompressEnd(bzs); - PyErr_SetString(PyExc_ValueError, - "couldn't find end of stream"); - Py_DECREF(ret); - return NULL; } } |