]> granicus.if.org Git - python/commitdiff
bpo-36946:Fix possible signed integer overflow when handling slices. (GH-15639)
authorHongWeipeng <hongweichen8888@sina.com>
Sun, 8 Sep 2019 10:15:56 +0000 (18:15 +0800)
committerSerhiy Storchaka <storchaka@gmail.com>
Sun, 8 Sep 2019 10:15:56 +0000 (13:15 +0300)
This is a complement to PR 13375.

Lib/test/test_list.py
Misc/NEWS.d/next/Core and Builtins/2019-09-02-16-17-42.bpo-36946._lAuSR.rst [new file with mode: 0644]
Modules/_ctypes/_ctypes.c
Objects/listobject.c

index c5002b12732c9876829da8cc7a4e42271578454e..fe4b2cd365f08894f7932b01b82e813576cb48cb 100644 (file)
@@ -150,6 +150,11 @@ class ListTest(list_tests.CommonTest):
             a[:] = data
             self.assertEqual(list(it), [])
 
+    def test_step_overflow(self):
+        a = [0, 1, 2, 3, 4]
+        a[1::sys.maxsize] = [0]
+        self.assertEqual(a[3::sys.maxsize], [3])
+
     def test_no_comdat_folding(self):
         # Issue 8847: In the PGO build, the MSVC linker's COMDAT folding
         # optimization causes failures in code that relies on distinct
diff --git a/Misc/NEWS.d/next/Core and Builtins/2019-09-02-16-17-42.bpo-36946._lAuSR.rst b/Misc/NEWS.d/next/Core and Builtins/2019-09-02-16-17-42.bpo-36946._lAuSR.rst
new file mode 100644 (file)
index 0000000..e0c5d71
--- /dev/null
@@ -0,0 +1 @@
+Fix possible signed integer overflow when handling slices. Patch by hongweipeng.
index 95bfe9d6348e6546dc6576295c94e36fda4c4150..d2f6391fa6dbd9df71926e6ec940f917776bb22b 100644 (file)
@@ -5195,7 +5195,8 @@ Pointer_subscript(PyObject *myself, PyObject *item)
         PyObject *np;
         StgDictObject *stgdict, *itemdict;
         PyObject *proto;
-        Py_ssize_t i, len, cur;
+        Py_ssize_t i, len;
+        size_t cur;
 
         /* Since pointers have no length, and we want to apply
            different semantics to negative indices than normal
index 5fca08ea363a412631d14095e1c1f92c1e08dd70..645742b801fac43b2a4de780636d506a0f80ad35 100644 (file)
@@ -2789,7 +2789,8 @@ list_subscript(PyListObject* self, PyObject* item)
         return list_item(self, i);
     }
     else if (PySlice_Check(item)) {
-        Py_ssize_t start, stop, step, slicelength, cur, i;
+        Py_ssize_t start, stop, step, slicelength, i;
+        size_t cur;
         PyObject* result;
         PyObject* it;
         PyObject **src, **dest;
@@ -2925,7 +2926,8 @@ list_ass_subscript(PyListObject* self, PyObject* item, PyObject* value)
             /* assign slice */
             PyObject *ins, *seq;
             PyObject **garbage, **seqitems, **selfitems;
-            Py_ssize_t cur, i;
+            Py_ssize_t i;
+            size_t cur;
 
             /* protect against a[::-1] = a */
             if (self == (PyListObject*)value) {