From: Mark Dickinson Date: Sat, 6 Oct 2012 17:50:02 +0000 (+0100) Subject: Issue #16096: Fix signed overflow in Objects/longobject.c. Thanks Serhiy Storchaka. X-Git-Tag: v3.4.0a1~2336^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=fc9adb62fbfa8d2f81f7224afea43557a4fff409;p=python Issue #16096: Fix signed overflow in Objects/longobject.c. Thanks Serhiy Storchaka. --- diff --git a/Objects/longobject.c b/Objects/longobject.c index 73413dd5af..4cc080f2b5 100644 --- a/Objects/longobject.c +++ b/Objects/longobject.c @@ -668,10 +668,9 @@ _PyLong_NumBits(PyObject *vv) assert(ndigits == 0 || v->ob_digit[ndigits - 1] != 0); if (ndigits > 0) { digit msd = v->ob_digit[ndigits - 1]; - - result = (ndigits - 1) * PyLong_SHIFT; - if (result / PyLong_SHIFT != (size_t)(ndigits - 1)) + if ((size_t)(ndigits - 1) > PY_SIZE_MAX / (size_t)PyLong_SHIFT) goto Overflow; + result = (size_t)(ndigits - 1) * (size_t)PyLong_SHIFT; do { ++result; if (result == 0)