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/binascii.c | |
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/binascii.c')
-rw-r--r-- | Modules/binascii.c | 16 |
1 files changed, 8 insertions, 8 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 |