]> granicus.if.org Git - python/commitdiff
Fix zlib crash from zlib.decompressobj().flush(val) when val was not positive.
authorGregory P. Smith <greg@mad-scientist.com>
Wed, 9 Apr 2008 00:25:17 +0000 (00:25 +0000)
committerGregory P. Smith <greg@mad-scientist.com>
Wed, 9 Apr 2008 00:25:17 +0000 (00:25 +0000)
It tried to allocate negative or zero memory.  That fails.

Lib/test/test_zlib.py
Modules/zlibmodule.c

index 0c96842c77a7304f4e45f9fe36570f1bf100e1a2..adb87ff0faf045b75b3ed41c38ac62f29af630c8 100644 (file)
@@ -83,6 +83,11 @@ class ExceptionTestCase(unittest.TestCase):
         # verify failure on building decompress object with bad params
         self.assertRaises(ValueError, zlib.decompressobj, 0)
 
+    def test_decompressobj_badflush(self):
+        # verify failure on calling decompressobj.flush with bad params
+        self.assertRaises(ValueError, zlib.decompressobj().flush, 0)
+        self.assertRaises(ValueError, zlib.decompressobj().flush, -1)
+
 
 
 class CompressTestCase(unittest.TestCase):
index f59343f298a986fe976a52d604a2dfcebfb40083..4f78dbcb15dabaf2952bee247abfc9d3127558f1 100644 (file)
@@ -774,6 +774,10 @@ PyZlib_unflush(compobject *self, PyObject *args)
 
     if (!PyArg_ParseTuple(args, "|i:flush", &length))
        return NULL;
+    if (length <= 0) {
+       PyErr_SetString(PyExc_ValueError, "length must be greater than zero");
+       return NULL;
+    }
     if (!(retval = PyString_FromStringAndSize(NULL, length)))
        return NULL;