mirror of https://github.com/python/cpython
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).
This commit is contained in:
parent
04530812e9
commit
05f16416d9
|
@ -389,6 +389,10 @@ class OperatorsTest(unittest.TestCase):
|
||||||
a.setstate(100)
|
a.setstate(100)
|
||||||
self.assertEqual(a.getstate(), 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):
|
class ClassPropertiesAndMethods(unittest.TestCase):
|
||||||
|
|
||||||
def assertHasAttr(self, obj, name):
|
def assertHasAttr(self, obj, name):
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
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);
|
res = (*func)(self);
|
||||||
if (res == -1 && PyErr_Occurred())
|
if (res == -1 && PyErr_Occurred())
|
||||||
return NULL;
|
return NULL;
|
||||||
return PyLong_FromLong((long)res);
|
return PyLong_FromSsize_t(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
|
Loading…
Reference in New Issue