Skip to content
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
24 changes: 23 additions & 1 deletion Lib/test/test_asyncio/test_futures.py
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ def __eq__(self, other):

fut.remove_done_callback(evil())

def test_schedule_callbacks_list_mutation(self):
def test_schedule_callbacks_list_mutation_1(self):
# see http://bugs.python.org/issue28963 for details

def mut(f):
Expand All @@ -606,6 +606,28 @@ def mut(f):
fut.set_result(1)
test_utils.run_briefly(self.loop)

def test_schedule_callbacks_list_mutation_2(self):
# see http://bugs.python.org/issue30828 for details

fut = self._new_future()
fut.add_done_callback(str)

for _ in range(63):
fut.add_done_callback(id)

max_extra_cbs = 100
extra_cbs = 0

class evil:
def __eq__(self, other):
nonlocal extra_cbs
extra_cbs += 1
if extra_cbs < max_extra_cbs:
fut.add_done_callback(id)
return False

fut.remove_done_callback(evil())


@unittest.skipUnless(hasattr(futures, '_CFuture'),
'requires the C _asyncio module')
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix out of bounds write in `asyncio.CFuture.remove_done_callback()`.
13 changes: 10 additions & 3 deletions Modules/_asynciomodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -531,9 +531,16 @@ _asyncio_Future_remove_done_callback(FutureObj *self, PyObject *fn)
goto fail;
}
if (ret == 0) {
Py_INCREF(item);
PyList_SET_ITEM(newlist, j, item);
j++;
if (j < len) {
Py_INCREF(item);
PyList_SET_ITEM(newlist, j, item);
j++;
}
else {
if (PyList_Append(newlist, item)) {
goto fail;
}
}
}
}

Expand Down