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
|
@ -869,19 +869,25 @@ binascii_crc32(PyObject *self, PyObject *args)
|
|||
if ( !PyArg_ParseTuple(args, "s#|l:crc32", &bin_data, &len, &crc) )
|
||||
return NULL;
|
||||
|
||||
crc = crc ^ 0xFFFFFFFFUL;
|
||||
crc = ~ crc;
|
||||
#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);
|
||||
/* Note: (crc >> 8) MUST zero fill on left */
|
||||
|
||||
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.
|
||||
#if SIZEOF_LONG > 4
|
||||
/* 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 unsigned 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));
|
||||
#endif
|
||||
return PyInt_FromLong(result);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue