mirror of
https://github.com/python/cpython.git
synced 2025-09-27 02:39:58 +00:00
Another stab at SF 576327: zipfile when sizeof(long) == 8
binascii_crc32(): The previous patch forced this to return the same result across platforms. This patch deals with that, on a 64-bit box, the *entry* value may have "unexpected" bits in the high four bytes. Bugfix candidate.
This commit is contained in:
parent
aab713bdf7
commit
934c1a1c6b
1 changed files with 104 additions and 98 deletions
|
@ -869,19 +869,25 @@ binascii_crc32(PyObject *self, PyObject *args)
|
||||||
if ( !PyArg_ParseTuple(args, "s#|l:crc32", &bin_data, &len, &crc) )
|
if ( !PyArg_ParseTuple(args, "s#|l:crc32", &bin_data, &len, &crc) )
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
crc = crc ^ 0xFFFFFFFFUL;
|
crc = ~ crc;
|
||||||
while(len--)
|
#if SIZEOF_LONG > 4
|
||||||
|
/* only want the trailing 32 bits */
|
||||||
|
crc &= 0xFFFFFFFFUL;
|
||||||
|
#endif
|
||||||
|
while (len--)
|
||||||
crc = crc_32_tab[(crc ^ *bin_data++) & 0xffUL] ^ (crc >> 8);
|
crc = crc_32_tab[(crc ^ *bin_data++) & 0xffUL] ^ (crc >> 8);
|
||||||
/* Note: (crc >> 8) MUST zero fill on left */
|
/* Note: (crc >> 8) MUST zero fill on left */
|
||||||
|
|
||||||
result = (long)(crc ^ 0xFFFFFFFFUL);
|
result = (long)(crc ^ 0xFFFFFFFFUL);
|
||||||
/* If long is > 32 bits, extend the sign bit. This is one way to
|
#if SIZEOF_LONG > 4
|
||||||
* ensure the result is the same across platforms. The other way
|
/* Extend the sign bit. This is one way to ensure the result is the
|
||||||
* would be to return an unbounded long, but the evidence suggests
|
* same across platforms. The other way would be to return an
|
||||||
* that lots of code outside this treats the result as if it were
|
* unbounded unsigned long, but the evidence suggests that lots of
|
||||||
* a signed 4-byte integer.
|
* code outside this treats the result as if it were a signed 4-byte
|
||||||
|
* integer.
|
||||||
*/
|
*/
|
||||||
result |= -(result & (1L << 31));
|
result |= -(result & (1L << 31));
|
||||||
|
#endif
|
||||||
return PyInt_FromLong(result);
|
return PyInt_FromLong(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue