Skip to content

gh-154817: Fix OrderedDict.pop() crash with inconsistent equality - #154818

Open
BHUVANSH855 wants to merge 1 commit into
python:mainfrom
BHUVANSH855:fix-odict-pop-null-failobj
Open

gh-154817: Fix OrderedDict.pop() crash with inconsistent equality#154818
BHUVANSH855 wants to merge 1 commit into
python:mainfrom
BHUVANSH855:fix-odict-pop-null-failobj

Conversation

@BHUVANSH855

Copy link
Copy Markdown
Contributor

Summary

Fix a crash in collections.OrderedDict.pop() when a key's __eq__
implementation returns inconsistent results across repeated comparisons.

If the initial lookup succeeds but the subsequent removal lookup fails,
and no default value is supplied, OrderedDict.pop() could dereference
a NULL default value and crash the interpreter.

This change raises KeyError instead and adds a regression test covering
this scenario.

Changes

  • Fix the missing-key path in OrderedDict.pop() when no default value is provided.
  • Add a regression test for a key with stateful equality.

Testing

./python -m test test_ordered_dict
./python -m test test_collections

Closes gh-154817

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OrderedDict.pop() can segfault when key equality changes between lookups

1 participant