Crash in PyDict_AsFrozenDictAndClear() with obj.__dict__

Offen
#161,767 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Anfängerfreundlichkeit
35/100
Issue-Typ
Bug
Klarheit
Größtenteils klar
Aktivitätsstatus
Veraltet
Tech-Stack
python
Bereich
backend

Rechercherichtung

Read the crash reproducer in the issue and inspect the relevant dict handling in Objects/dictobject.c, where the debug assertion fails. Start by tracing how PyDict_AsFrozenDictAndClear() handles instance dictionaries with inline values; done means the assertion passes and the frozen dictionary remains valid after mutating or deleting the original instance. The issue lists linked PR gh-161768, so check its status before starting.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

interpreter-core topic-C-API type-crash
Crash report

The frozendict C API crashes when given an instance __dict__ that still has inline values:

import _testcapi
class A: pass
a = A(); a.x = 1; a.y = 2
f = _testcapi.dict_as_frozendict_and_clear(a.__dict__)
a.x = 'MUTATED'
print(f)

Debug build fails an assertion in Objects/dictobject.c. The keys are moved to the frozendict but the values stay in the object's inline values, so both end up sharing them (use-after-free after del a).

CPython versions tested on:

CPython main branch

Operating systems tested on:

Windows

Output from running 'python -VV' on the command line:

Python 3.16.0a1+dev (heads/main:9d05428, Nov 10 2026, 19:53:18) [MSC v.1951 64 bit (AMD64)]

Linked PRs
  • gh-161768
Vorherrschende Sprache
Python
Sterne
78.2k
Forks
36.6k
Ø Merge
19 Std. 57 Min.
Gemergte PRs (30 T.)
630

Entwicklungsumgebung

In Codespaces öffnen

Startet den Dev-Container des Projekts im Browser, mit Ihrem eigenen GitHub-Konto.

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus python/cpython

Alle Issues in python/cpython

Ähnliche Issues

Weitere Issues zu Python

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.