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

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

index 4440942ac9d7939c84415eed89be2885f9c52345..6b3b12eccc299d4ecf872ef389337441d725f401 100644 (file)
@@ -71,6 +71,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 8cadcbc52cbdc3f8be1132b67cf5e4b610a138bc..aff165c361342c2c58cefe6c44318431158105d8 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;