Skip to content
Closed
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Detect mutated list in list_slice(): check if the list size changed
before/after allocating a new list object to prevent a crash.
16 changes: 11 additions & 5 deletions Objects/listobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -436,20 +436,26 @@ list_slice(PyListObject *a, Py_ssize_t ilow, Py_ssize_t ihigh)
{
PyListObject *np;
PyObject **src, **dest;
Py_ssize_t i, len;
Py_ssize_t alen, i, len;
alen = Py_SIZE(a);
if (ilow < 0)
ilow = 0;
else if (ilow > Py_SIZE(a))
ilow = Py_SIZE(a);
else if (ilow > alen)
ilow = alen;
if (ihigh < ilow)
ihigh = ilow;
else if (ihigh > Py_SIZE(a))
ihigh = Py_SIZE(a);
else if (ihigh > alen)
ihigh = alen;
len = ihigh - ilow;
np = (PyListObject *) PyList_New(len);
if (np == NULL)
return NULL;

if (Py_SIZE(a) != alen) {
PyErr_SetString(PyExc_RuntimeError, "list mutated during slicing");
return NULL;
}

src = a->ob_item + ilow;
dest = np->ob_item;
for (i = 0; i < len; i++) {
Expand Down