OrderedDict.pop() can segfault when key equality changes between lookups
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 77.2k
- Forks
- 35.9k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
Crash report
What happened?
Calling collections.OrderedDict.pop() without a default value can cause a segmentation fault if the lookup key has a stateful __eq__ implementation that returns different results across successive comparisons.
The crash occurs on the current main branch.
Minimal reproducer:
from collections import OrderedDict
class K:
def __init__(self):
self.calls = 0
def __hash__(self):
return 12345
def __eq__(self, other):
self.calls += 1
return self.calls == 1
k1 = K()
k2 = K()
od = OrderedDict()
od[k1] = "value"
od.pop(k2)
Running this with a locally built CPython from main results in:
Segmentation fault (core dumped)
Expected behavior:
OrderedDict.pop()should not crash the interpreter.- It should either remove the matching item or raise
KeyErrorif the key is not found.
CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux
Output from running 'python -VV' on the command line:
Python 3.16.0a0 (heads/fix-odict-pop-null-failobj:2ffab083782, Jul 28 2026, 12:31:11) [GCC 13.3.0]
Linked PRs
- gh-154818
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne mit dem OrderedDict.pop()-Einstiegspunkt und führe den minimalen Reproducer auf einem lokal gebauten CPython-main-Branch aus. Als abgeschlossen gilt die Aufgabe, wenn der Reproducer nicht mehr mit einem Segmentation Fault abstürzt und pop() entweder das passende Element entfernt oder KeyError auslöst, wenn kein Schlüssel gefunden wird.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- backend
- Issue-Typ
- Bug
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Klar beschrieben
- Anfängerfreundlichkeit
- 25/100