diff --git a/Modules/_asynciomodule.c b/Modules/_asynciomodule.c index b8a88e61d4..8c7dbd2e0b 100644 --- a/Modules/_asynciomodule.c +++ b/Modules/_asynciomodule.c @@ -531,6 +531,11 @@ _asyncio_Future_remove_done_callback(FutureObj *self, PyObject *fn) if ((ret = PyObject_RichCompareBool(fn, item, Py_EQ)) < 0) { goto fail; } + if (j >= len) { + PyErr_SetString(PyExc_RuntimeError, + "Done callbacks modified while iterating."); + goto fail; + } if (ret == 0) { Py_INCREF(item); PyList_SET_ITEM(newlist, j, item);