--- ./Modules/zlibmodule.c.orig 2008-08-03 13:25:30.000000000 -0500 +++ ./Modules/zlibmodule.c 2008-08-03 13:25:39.000000000 -0500 @@ -667,6 +667,10 @@ 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; --- ./Lib/test/test_zlib.py.orig 2008-08-03 13:25:30.000000000 -0500 +++ ./Lib/test/test_zlib.py 2008-08-03 13:25:39.000000000 -0500 @@ -71,6 +71,11 @@ # 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):