summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2017-10-03 11:13:44 (GMT)
committerGitHub <noreply@github.com>2017-10-03 11:13:44 (GMT)
commit85c0b8941f0c8ef3ed787c9d504712c6ad3eb5d3 (patch)
tree0b5ed0847156a9397d7b8bbee4ed6349a689172c /Objects
parent1a87de7fcfa3c19f08e29047337c350b4a32b259 (diff)
downloadcpython-85c0b8941f0c8ef3ed787c9d504712c6ad3eb5d3.zip
cpython-85c0b8941f0c8ef3ed787c9d504712c6ad3eb5d3.tar.gz
cpython-85c0b8941f0c8ef3ed787c9d504712c6ad3eb5d3.tar.bz2
bpo-31619: Fixed a ValueError when convert a string with large number of underscores (#3827)
to integer with binary base.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/longobject.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/Objects/longobject.c b/Objects/longobject.c
index 3b07585..c71b783 100644
--- a/Objects/longobject.c
+++ b/Objects/longobject.c
@@ -2057,15 +2057,15 @@ long_from_binary_base(const char **str, int base, PyLongObject **res)
}
*str = p;
- /* n <- # of Python digits needed, = ceiling(n/PyLong_SHIFT). */
- n = digits * bits_per_char + PyLong_SHIFT - 1;
- if (n / bits_per_char < p - start) {
+ /* n <- the number of Python digits needed,
+ = ceiling((digits * bits_per_char) / PyLong_SHIFT). */
+ if (digits > (PY_SSIZE_T_MAX - (PyLong_SHIFT - 1)) / bits_per_char) {
PyErr_SetString(PyExc_ValueError,
"int string too large to convert");
*res = NULL;
return 0;
}
- n = n / PyLong_SHIFT;
+ n = (digits * bits_per_char + PyLong_SHIFT - 1) / PyLong_SHIFT;
z = _PyLong_New(n);
if (z == NULL) {
*res = NULL;