diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2015-04-20 06:26:49 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2015-04-20 06:26:49 (GMT) |
commit | 2ef7c478444f453a04ae63ecc3d3de07915ad2b0 (patch) | |
tree | b270c71c80ddff387458d526c8566b2c8f9e0672 /Modules | |
parent | 16b2e4f5480bb46a025f9d3a917a923e7f7f59f1 (diff) | |
download | cpython-2ef7c478444f453a04ae63ecc3d3de07915ad2b0.zip cpython-2ef7c478444f453a04ae63ecc3d3de07915ad2b0.tar.gz cpython-2ef7c478444f453a04ae63ecc3d3de07915ad2b0.tar.bz2 |
Issue #23728: binascii.crc_hqx() could return an integer outside of the range
0-0xffff for empty data.
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/binascii.c | 16 | ||||
-rw-r--r-- | Modules/clinic/binascii.c.h | 14 |
2 files changed, 15 insertions, 15 deletions
diff --git a/Modules/binascii.c b/Modules/binascii.c index 4e6953b..ea14d3c 100644 --- a/Modules/binascii.c +++ b/Modules/binascii.c @@ -909,31 +909,31 @@ binascii_rledecode_hqx_impl(PyModuleDef *module, Py_buffer *data) /*[clinic input] -binascii.crc_hqx -> int +binascii.crc_hqx -> unsigned_int data: Py_buffer - crc: int + crc: unsigned_int(bitwise=True) / Compute hqx CRC incrementally. [clinic start generated code]*/ -static int -binascii_crc_hqx_impl(PyModuleDef *module, Py_buffer *data, int crc) -/*[clinic end generated code: output=634dac18dfa863d7 input=68060931b2f51c8a]*/ +static unsigned int +binascii_crc_hqx_impl(PyModuleDef *module, Py_buffer *data, unsigned int crc) +/*[clinic end generated code: output=167c2dac62625717 input=add8c53712ccceda]*/ { unsigned char *bin_data; - unsigned int ucrc = (unsigned int)crc; Py_ssize_t len; + crc &= 0xffff; bin_data = data->buf; len = data->len; while(len-- > 0) { - ucrc=((ucrc<<8)&0xff00)^crctab_hqx[((ucrc>>8)&0xff)^*bin_data++]; + crc = ((crc<<8)&0xff00) ^ crctab_hqx[(crc>>8)^*bin_data++]; } - return (int)ucrc; + return crc; } #ifndef USE_ZLIB_CRC32 diff --git a/Modules/clinic/binascii.c.h b/Modules/clinic/binascii.c.h index f647032..ef646dd 100644 --- a/Modules/clinic/binascii.c.h +++ b/Modules/clinic/binascii.c.h @@ -267,25 +267,25 @@ PyDoc_STRVAR(binascii_crc_hqx__doc__, #define BINASCII_CRC_HQX_METHODDEF \ {"crc_hqx", (PyCFunction)binascii_crc_hqx, METH_VARARGS, binascii_crc_hqx__doc__}, -static int -binascii_crc_hqx_impl(PyModuleDef *module, Py_buffer *data, int crc); +static unsigned int +binascii_crc_hqx_impl(PyModuleDef *module, Py_buffer *data, unsigned int crc); static PyObject * binascii_crc_hqx(PyModuleDef *module, PyObject *args) { PyObject *return_value = NULL; Py_buffer data = {NULL, NULL}; - int crc; - int _return_value; + unsigned int crc; + unsigned int _return_value; if (!PyArg_ParseTuple(args, - "y*i:crc_hqx", + "y*I:crc_hqx", &data, &crc)) goto exit; _return_value = binascii_crc_hqx_impl(module, &data, crc); if ((_return_value == -1) && PyErr_Occurred()) goto exit; - return_value = PyLong_FromLong((long)_return_value); + return_value = PyLong_FromUnsignedLong((unsigned long)_return_value); exit: /* Cleanup for data */ @@ -543,4 +543,4 @@ exit: return return_value; } -/*[clinic end generated code: output=e46d29f8c9adae7e input=a9049054013a1b77]*/ +/*[clinic end generated code: output=22761b36f4f9e5bb input=a9049054013a1b77]*/ |