Commit 05f16416 authored by Zackery Spytz's avatar Zackery Spytz Committed by Victor Stinner

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

Fix possible overflow in wrap_lenfunc() when
sizeof(long) < sizeof(Py_ssize_t) (e.g., 64-bit Windows).
parent 04530812
......@@ -389,6 +389,10 @@ class OperatorsTest(unittest.TestCase):
a.setstate(100)
self.assertEqual(a.getstate(), 100)
def test_wrap_lenfunc_bad_cast(self):
self.assertEqual(range(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).
......@@ -5536,7 +5536,7 @@ wrap_lenfunc(PyObject *self, PyObject *args, void *wrapped)
res = (*func)(self);
if (res == -1 && PyErr_Occurred())
return NULL;
return PyLong_FromLong((long)res);
return PyLong_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