]> granicus.if.org Git - python/commitdiff
Bug #1622896: fix a rare corner case where the bz2 module raised an
authorGeorg Brandl <georg@python.org>
Tue, 13 Mar 2007 12:34:35 +0000 (12:34 +0000)
committerGeorg Brandl <georg@python.org>
Tue, 13 Mar 2007 12:34:35 +0000 (12:34 +0000)
error in spite of a succesful compression.
 (backport from rev. 54336)

Misc/NEWS
Modules/bz2module.c

index 5e44c2592959fb0c1f6655796a0b6711dae17696..d94b0f79accc8f7badddd71a7c34d2146e0c1a4b 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -125,6 +125,9 @@ Core and builtins
 Extension Modules
 -----------------
 
+- Bug #1622896: fix a rare corner case where the bz2 module raised an
+  error in spite of a succesful compression.
+
 - Patch #1654417: make operator.{get,set,del}slice use the full range
   of Py_ssize_t.
 
index 7a7d6cb11f0176d5b4c86e24109b1f850e4cf565..9d92cf6bb4028df9da266fef2ee06cfc27198178 100644 (file)
@@ -1579,6 +1579,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) {
@@ -1588,8 +1590,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;
                }
        }
 
@@ -1871,6 +1871,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) {
@@ -1881,8 +1883,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;
                }
        }
 
@@ -2160,6 +2160,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) {
@@ -2169,12 +2176,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;
                }
        }