Skip to content

[3.7] bpo-36946:Fix possible signed integer overflow when handling slices. (GH-15639) #15729

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Lib/test/test_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,11 @@ def test_reversed_pickle(self):
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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix possible signed integer overflow when handling slices. Patch by hongweipeng.
3 changes: 2 additions & 1 deletion Modules/_ctypes/_ctypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -5019,7 +5019,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
Expand Down
6 changes: 4 additions & 2 deletions Objects/listobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -2729,7 +2729,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;
Expand Down Expand Up @@ -2865,7 +2866,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) {
Expand Down