From: Andrew M. Kuchling Date: Tue, 22 Nov 2005 15:39:05 +0000 (+0000) Subject: [Patch #1350573] zlib.crc32 doesn't handle 0xffffffff seed. Add tests and bugfix... X-Git-Tag: v2.4.3c1~210 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=4e2a4ff6079db5e2115d8879fa511ecde161eae9;p=thirdparty%2FPython%2Fcpython.git [Patch #1350573] zlib.crc32 doesn't handle 0xffffffff seed. Add tests and bugfix. Bug reported by John Schmidt; bugfix by Danny Yoo. --- diff --git a/Lib/test/test_zlib.py b/Lib/test/test_zlib.py index e91184e1b718..7634680ecfe8 100644 --- a/Lib/test/test_zlib.py +++ b/Lib/test/test_zlib.py @@ -24,6 +24,7 @@ class ChecksumTestCase(unittest.TestCase): # checksum test cases def test_crc32start(self): self.assertEqual(zlib.crc32(""), zlib.crc32("", 0)) + self.assert_(zlib.crc32("abc", 0xffffffff)) def test_crc32empty(self): self.assertEqual(zlib.crc32("", 0), 0) @@ -32,6 +33,7 @@ class ChecksumTestCase(unittest.TestCase): def test_adler32start(self): self.assertEqual(zlib.adler32(""), zlib.adler32("", 1)) + self.assert_(zlib.adler32("abc", 0xffffffff)) def test_adler32empty(self): self.assertEqual(zlib.adler32("", 0), 0) diff --git a/Modules/zlibmodule.c b/Modules/zlibmodule.c index c3238a068501..a598ae31c31f 100644 --- a/Modules/zlibmodule.c +++ b/Modules/zlibmodule.c @@ -778,7 +778,7 @@ PyZlib_adler32(PyObject *self, PyObject *args) Byte *buf; int len; - if (!PyArg_ParseTuple(args, "s#|l:adler32", &buf, &len, &adler32val)) + if (!PyArg_ParseTuple(args, "s#|k:adler32", &buf, &len, &adler32val)) return NULL; adler32val = adler32(adler32val, buf, len); return PyInt_FromLong(adler32val); @@ -796,7 +796,7 @@ PyZlib_crc32(PyObject *self, PyObject *args) uLong crc32val = crc32(0L, Z_NULL, 0); Byte *buf; int len; - if (!PyArg_ParseTuple(args, "s#|l:crc32", &buf, &len, &crc32val)) + if (!PyArg_ParseTuple(args, "s#|k:crc32", &buf, &len, &crc32val)) return NULL; crc32val = crc32(crc32val, buf, len); return PyInt_FromLong(crc32val);