bpo-26423: Fix possible overflow in wrap_lenfunc() (GH-13606) · python/cpython@05f1641 (original) (raw)
File tree
3 files changed
lines changed
- Misc/NEWS.d/next/Core and Builtins
3 files changed
lines changed
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -389,6 +389,10 @@ def foo(self): return 1 | ||
389 | 389 | a.setstate(100) |
390 | 390 | self.assertEqual(a.getstate(), 100) |
391 | 391 | |
392 | +def test_wrap_lenfunc_bad_cast(self): | |
393 | +self.assertEqual(range(sys.maxsize).__len__(), sys.maxsize) | |
394 | + | |
395 | + | |
392 | 396 | class ClassPropertiesAndMethods(unittest.TestCase): |
393 | 397 | |
394 | 398 | def assertHasAttr(self, obj, name): |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
1 | +Fix possible overflow in ``wrap_lenfunc()`` when | |
2 | +``sizeof(long) < sizeof(Py_ssize_t)`` (e.g., 64-bit Windows). |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -5536,7 +5536,7 @@ wrap_lenfunc(PyObject *self, PyObject *args, void *wrapped) | ||
5536 | 5536 | res = (*func)(self); |
5537 | 5537 | if (res == -1 && PyErr_Occurred()) |
5538 | 5538 | return NULL; |
5539 | -return PyLong_FromLong((long)res); | |
5539 | +return PyLong_FromSsize_t(res); | |
5540 | 5540 | } |
5541 | 5541 | |
5542 | 5542 | static PyObject * |