Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Avoid potential undefined behaviour from overflow
  • Loading branch information
mdickinson committed Sep 3, 2022
commit d16db91dcccc7b0e5fb8b7c0f339190132b7c042
6 changes: 4 additions & 2 deletions Objects/longobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -1765,8 +1765,10 @@ long_to_decimal_string_internal(PyObject *aa,
/ (3 * PyLong_SHIFT) + 2) {
PyInterpreterState *interp = _PyInterpreterState_GET();
int max_str_digits = interp->int_max_str_digits;
if ((max_str_digits > 0) && (size_a >= 10 * max_str_digits
/ (3 * PyLong_SHIFT) + 2)) {
if ((max_str_digits > 0) &&
/* avoid overflow in 10 * max_str_digits */
(max_str_digits <= INT_MAX / 10) &&
Comment thread
mdickinson marked this conversation as resolved.
Outdated
(size_a >= 10 * max_str_digits / (3 * PyLong_SHIFT) + 2)) {
PyErr_Format(PyExc_ValueError, _MAX_STR_DIGITS_ERROR_FMT2,
max_str_digits);
return -1;
Expand Down