Skip to content

Commit fc9adb6

Browse files
committed
Issue #16096: Fix signed overflow in Objects/longobject.c. Thanks Serhiy Storchaka.
1 parent c04ddff commit fc9adb6

1 file changed

Lines changed: 2 additions & 3 deletions

File tree

Objects/longobject.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -668,10 +668,9 @@ _PyLong_NumBits(PyObject *vv)
668668
assert(ndigits == 0 || v->ob_digit[ndigits - 1] != 0);
669669
if (ndigits > 0) {
670670
digit msd = v->ob_digit[ndigits - 1];
671-
672-
result = (ndigits - 1) * PyLong_SHIFT;
673-
if (result / PyLong_SHIFT != (size_t)(ndigits - 1))
671+
if ((size_t)(ndigits - 1) > PY_SIZE_MAX / (size_t)PyLong_SHIFT)
674672
goto Overflow;
673+
result = (size_t)(ndigits - 1) * (size_t)PyLong_SHIFT;
675674
do {
676675
++result;
677676
if (result == 0)

0 commit comments

Comments
 (0)