diff options
| author | Michael W. Hudson <mwh@python.net> | 2002-09-25 10:22:50 (GMT) |
|---|---|---|
| committer | Michael W. Hudson <mwh@python.net> | 2002-09-25 10:22:50 (GMT) |
| commit | f5cdacfa91067594de16028e057eace3e8c30040 (patch) | |
| tree | 781f5e3053dc8ca63acce65613cca0f09135590d /Modules | |
| parent | 74f1f76ef194cf3a722c56c46f73f16194b497d4 (diff) | |
| download | cpython-f5cdacfa91067594de16028e057eace3e8c30040.zip cpython-f5cdacfa91067594de16028e057eace3e8c30040.tar.gz cpython-f5cdacfa91067594de16028e057eace3e8c30040.tar.bz2 | |
backport tim_one's checkin of
revision 2.35 of binascii.c
Fix for SF bug #576327: zipfile when sizeof(long) == 8
binascii_crc32(): Make this return a signed 4-byte result across
platforms. The other way to make this platform-independent would be to
make it return an unsigned unbounded int, but the evidence suggests
other code out there treats it like a signed 4-byte int (e.g., existing
code writing the result with struct.pack "l" format).
Bugfix candidate.
Diffstat (limited to 'Modules')
| -rw-r--r-- | Modules/binascii.c | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/Modules/binascii.c b/Modules/binascii.c index 70d60f0..9d710f5 100644 --- a/Modules/binascii.c +++ b/Modules/binascii.c @@ -861,6 +861,7 @@ binascii_crc32(PyObject *self, PyObject *args) unsigned char *bin_data; unsigned long crc = 0UL; /* initial value of CRC */ int len; + long result; if ( !PyArg_ParseTuple(args, "s#|l:crc32", &bin_data, &len, &crc) ) return NULL; @@ -869,7 +870,16 @@ binascii_crc32(PyObject *self, PyObject *args) while(len--) crc = crc_32_tab[(crc ^ *bin_data++) & 0xffUL] ^ (crc >> 8); /* Note: (crc >> 8) MUST zero fill on left */ - return Py_BuildValue("l", crc ^ 0xFFFFFFFFUL); + + result = (long)(crc ^ 0xFFFFFFFFUL); + /* If long is > 32 bits, extend the sign bit. This is one way to + * ensure the result is the same across platforms. The other way + * would be to return an unbounded long, but the evidence suggests + * that lots of code outside this treats the result as if it were + * a signed 4-byte integer. + */ + result |= -(result & (1L << 31)); + return PyInt_FromLong(result); } |
