Commit 934c1a1c authored by Tim Peters's avatar Tim Peters

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.
parent aab713bd
...@@ -869,19 +869,25 @@ binascii_crc32(PyObject *self, PyObject *args) ...@@ -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);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment