Visitar URL original
GH-97592: Fix crash in C remove_done_callback due to evil code by gvanrossum · Pull Request #97660 · python/cpython · GitHub
Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add test
  • Loading branch information
gvanrossum committed Sep 29, 2022
commit 00b95363c1b045e1a9e8b52ad8aae95718bccd33
15 changes: 15 additions & 0 deletions Lib/test/test_asyncio/test_futures.py
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,21 @@ def __eq__(self, other):

fut.remove_done_callback(evil())

def test_remove_done_callbacks_list_clear(self):
# see https://github.com/python/cpython/issues/97592 for details

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

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

class evil:
def __eq__(self, other):
fut.remove_done_callback(other)

fut.remove_done_callback(evil())
Comment on lines +844 to +848

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Class names should normally use the CapWords convention.

Suggested change
class evil:
def __eq__(self, other):
fut.remove_done_callback(other)
fut.remove_done_callback(evil())
class Evil:
def __eq__(self, other):
fut.remove_done_callback(other)
fut.remove_done_callback(Evil())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All callbacks added by fut.add_done_callback() will be cleared when calling fut.remove_done_callback(Evil()), but the return value will be the number of callbacks added last.

I'm not sure if we need to improve the return value of remove done callback further, the current changes are good enough to fix the crash. :)


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

Expand Down