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

@BHUVANSH855 BHUVANSH855 commented Jul 28, 2026

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 of dereferencing the NULL default
value and adds a C implementation regression test covering this scenario.

The separate OrderedDict container desynchronization issue is tracked
in gh-154835.

Changes

  • Fix the missing-key path in OrderedDict.pop() when no default value is provided.
  • Raise KeyError instead of dereferencing a NULL default value.
  • Add a C implementation regression test for a key with stateful equality.

Testing

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

Closes gh-154817

Comment thread Lib/test/test_ordered_dict.py Outdated
@BHUVANSH855
BHUVANSH855 force-pushed the fix-odict-pop-null-failobj branch from 14077db to 8be2633 Compare July 28, 2026 17:57
@StanFromIreland

Copy link
Copy Markdown
Member

Please don't force-push: https://devguide.python.org/getting-started/pull-request-lifecycle/#don-t-force-push

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

2 participants