summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGregory P. Smith <greg@mad-scientist.com>2008-04-09 00:25:17 (GMT)
committerGregory P. Smith <greg@mad-scientist.com>2008-04-09 00:25:17 (GMT)
commit79e42a0e0817b9c9fc23b333524427662b33986d (patch)
tree5e61bf69ea3291250f08e8616665d941345057d4
parente41b0061dd908251a393f77b030c9e7308ecd5c5 (diff)
downloadcpython-79e42a0e0817b9c9fc23b333524427662b33986d.zip
cpython-79e42a0e0817b9c9fc23b333524427662b33986d.tar.gz
cpython-79e42a0e0817b9c9fc23b333524427662b33986d.tar.bz2
Fix zlib crash from zlib.decompressobj().flush(val) when val was not positive.
It tried to allocate negative or zero memory. That fails.
-rw-r--r--Lib/test/test_zlib.py5
-rw-r--r--Modules/zlibmodule.c4
2 files changed, 9 insertions, 0 deletions
diff --git a/Lib/test/test_zlib.py b/Lib/test/test_zlib.py
index 0c96842..adb87ff 100644
--- a/Lib/test/test_zlib.py
+++ b/Lib/test/test_zlib.py
@@ -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):
diff --git a/Modules/zlibmodule.c b/Modules/zlibmodule.c
index f59343f..4f78dbc 100644
--- a/Modules/zlibmodule.c
+++ b/Modules/zlibmodule.c
@@ -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;