Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2c40f64

Browse files
committed
Issue #18408: Fix list_ass_slice(), handle list_resize() failure
I tested the patch manually by injecting a fault using gdb: list items are correctly restored on failure.
1 parent 9007dd7 commit 2c40f64

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

Objects/listobject.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -644,9 +644,14 @@ list_ass_slice(PyListObject *a, Py_ssize_t ilow, Py_ssize_t ihigh, PyObject *v)
644644
memcpy(recycle, &item[ilow], s);
645645

646646
if (d < 0) { /* Delete -d items */
647-
memmove(&item[ihigh+d], &item[ihigh],
648-
(Py_SIZE(a) - ihigh)*sizeof(PyObject *));
649-
list_resize(a, Py_SIZE(a) + d);
647+
Py_ssize_t tail;
648+
tail = (Py_SIZE(a) - ihigh) * sizeof(PyObject *);
649+
memmove(&item[ihigh+d], &item[ihigh], tail);
650+
if (list_resize(a, Py_SIZE(a) + d) < 0) {
651+
memmove(&item[ihigh], &item[ihigh+d], tail);
652+
memcpy(&item[ilow], recycle, s);
653+
goto Error;
654+
}
650655
item = a->ob_item;
651656
}
652657
else if (d > 0) { /* Insert d items */

0 commit comments

Comments
 (0)