Skip to content

Commit b4f4d57

Browse files
bug: prevent race condition in list.remove
1 parent 72eca2a commit b4f4d57

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

Objects/listobject.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3390,6 +3390,11 @@ list_remove_impl(PyListObject *self, PyObject *value)
33903390
int cmp = PyObject_RichCompareBool(obj, value, Py_EQ);
33913391
Py_DECREF(obj);
33923392
if (cmp > 0) {
3393+
if (i >= Py_SIZE(self) || self->ob_item[i] != obj) {
3394+
PyErr_SetString(PyExc_RuntimeError,
3395+
"list mutated during remove");
3396+
return NULL;
3397+
}
33933398
if (list_ass_slice_lock_held(self, i, i+1, NULL) == 0)
33943399
Py_RETURN_NONE;
33953400
return NULL;

0 commit comments

Comments
 (0)