]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-26423: Fix possible overflow in wrap_lenfunc() (GH-13606)
authorZackery Spytz <zspytz@gmail.com>
Tue, 28 May 2019 12:55:29 +0000 (06:55 -0600)
committerVictor Stinner <vstinner@redhat.com>
Tue, 28 May 2019 12:55:28 +0000 (14:55 +0200)
Fix possible overflow in wrap_lenfunc() when
sizeof(long) < sizeof(Py_ssize_t) (e.g., 64-bit Windows).

Lib/test/test_descr.py
Misc/NEWS.d/next/Core and Builtins/2019-05-27-18-00-19.bpo-26423.RgUOE8.rst [new file with mode: 0644]
Objects/typeobject.c

index e37a98417f505cb257e9abcf0d1e6df92306e055..6b018ccc56fa1d3a8eae57813931f8f9a14f691c 100644 (file)
@@ -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):
diff --git a/Misc/NEWS.d/next/Core and Builtins/2019-05-27-18-00-19.bpo-26423.RgUOE8.rst b/Misc/NEWS.d/next/Core and Builtins/2019-05-27-18-00-19.bpo-26423.RgUOE8.rst
new file mode 100644 (file)
index 0000000..6bf2031
--- /dev/null
@@ -0,0 +1,2 @@
+Fix possible overflow in ``wrap_lenfunc()`` when
+``sizeof(long) < sizeof(Py_ssize_t)`` (e.g., 64-bit Windows).
index 06e045bd1597f0ab58d7fb0d61cb0a3db25195d5..c14cbad875b4437bbd1606132964e73bd03d1558 100644 (file)
@@ -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 *