[issue31619] Strange error when convert hexadecimal with underscores to int

Serhiy Storchaka report at bugs.python.org
Wed Oct 4 09:23:32 EDT 2017


Serhiy Storchaka <storchaka+cpython at gmail.com> added the comment:

I missed the issue mentioned by Mark msg303331. I looked at the type of n, and okay, it is Py_ssize_t. But I forgot to check the type of digits and bits_per_char, and it is int. My fix doesn't guard from integer overflow.

The following PR fixes this. It also tries to guard against integer overflow in other place. Unfortunately there is yet one issue with that code. The guard works on 32-bit platform, where the precision of double is large than the size of Py_size_t. But on 64-bit platform it is possible that (Py_ssize_t)(digits * log_base_BASE[base]) takes the value not enough for writing the result of the parsing, because its lowest bits are lost.

I know that converting str to int with non-binary base has nonlinear complexity.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue31619>
_______________________________________


More information about the Python-bugs-list mailing list