Commit 80dfe990 authored by Victor Stinner's avatar Victor Stinner Committed by GitHub

bpo-26423: Fix possible overflow in wrap_lenfunc() (GH-13606) (GH-13625)

Fix possible overflow in wrap_lenfunc() when
sizeof(long) < sizeof(Py_ssize_t) (e.g., 64-bit Windows).

(cherry picked from commit 05f16416)
parent d9d10458
......@@ -403,6 +403,10 @@ class OperatorsTest(unittest.TestCase):
a.setstate(100)
self.assertEqual(a.getstate(), 100)
def test_wrap_lenfunc_bad_cast(self):
self.assertEqual(xrange(sys.maxsize).__len__(), sys.maxsize)
class ClassPropertiesAndMethods(unittest.TestCase):
def assertHasAttr(self, obj, name):
......
Fix possible overflow in ``wrap_lenfunc()`` when
``sizeof(long) < sizeof(Py_ssize_t)`` (e.g., 64-bit Windows).
......@@ -4398,7 +4398,7 @@ wrap_lenfunc(PyObject *self, PyObject *args, void *wrapped)
res = (*func)(self);
if (res == -1 && PyErr_Occurred())
return NULL;
return PyInt_FromLong((long)res);
return PyInt_FromSsize_t(res);
}
static PyObject *
......
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