]> granicus.if.org Git - python/commitdiff
Patch #101810: check whether zst.avail_out is non-zero when getting
authorAndrew M. Kuchling <amk@amk.ca>
Mon, 9 Oct 2000 14:18:10 +0000 (14:18 +0000)
committerAndrew M. Kuchling <amk@amk.ca>
Mon, 9 Oct 2000 14:18:10 +0000 (14:18 +0000)
   a Z_BUF_ERROR while decompressing.  If it is, assume that this means
   the data being decompressed is bad and raise an exception, instead of
   just assuming that Z_BUF_ERROR always means that more space is required.

Modules/zlibmodule.c

index 9416528ad4cdfa9fc7c3291865a7c5e60ebac4c1..cb2a2e5c9716d015f69d7521ce30dfe7b08d2f42 100644 (file)
@@ -214,7 +214,21 @@ PyZlib_decompress(PyObject *self, PyObject *args)
         case(Z_STREAM_END):
            break;
        case(Z_BUF_ERROR):
-        case(Z_OK):
+           /*
+            * If there is at least 1 byte of room according to zst.avail_out
+            * and we get this error, assume that it means zlib cannot
+            * process the inflate call() due to an error in the data.
+            */
+           if (zst.avail_out > 0)
+            {
+              PyErr_Format(ZlibError, "Error %i while decompressing data",
+                           err);
+              inflateEnd(&zst);
+              Py_DECREF(result_str);
+              return NULL;
+            }
+           /* fall through */
+       case(Z_OK):
            /* need more memory */
            if (_PyString_Resize(&result_str, r_strlen << 1) == -1)
             {