python / python/cpython

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

Abierto
#154,817 2 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

interpreter-core type-crash
Lenguaje dominante
Python
Estrellas
77.2k
Forks
35.9k
Métricas de merge de PR
Métricas de PR pendientes

Descripción

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 KeyError if 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

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Empieza con el punto de entrada OrderedDict.pop() y ejecuta el reproductor mínimo en una rama main de CPython compilada localmente. Se considera terminado cuando el reproductor ya no termina con un segmentation fault y pop() elimina el elemento coincidente o lanza KeyError cuando no se encuentra ninguna clave.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
python
Área
backend
Tipo de issue
Error
Dificultad
3/5
Tiempo estimado
1-2 días
Estado de actividad
Estancado
Claridad
Bien especificado
Aptitud para principiantes
25/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.