Unverified Kaydet (Commit) b7e483b6 authored tarafından Miss Islington (bot)'s avatar Miss Islington (bot) Kaydeden (comit) GitHub

bpo-36791: Safer detection of integer overflow in sum(). (GH-13080)

(cherry picked from commit 29500737)
Co-authored-by: 's avatarSerhiy Storchaka <storchaka@gmail.com>
üst 4f5febdf
......@@ -2374,9 +2374,11 @@ builtin_sum_impl(PyObject *module, PyObject *iterable, PyObject *start)
}
if (PyLong_CheckExact(item)) {
long b = PyLong_AsLongAndOverflow(item, &overflow);
long x = i_result + b;
if (overflow == 0 && ((x^i_result) >= 0 || (x^b) >= 0)) {
i_result = x;
if (overflow == 0 &&
(i_result >= 0 ? (b <= LONG_MAX - i_result)
: (b >= LONG_MIN - i_result)))
{
i_result += b;
Py_DECREF(item);
continue;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment