python / python/cpython

dtrace: debug abort importing module with lone surrogate unicode char in name while DTrace import probe is active

Offen
#156,118 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

interpreter-core type-crash
Vorherrschende Sprache
Python
Sterne
77.2k
Forks
35.9k
PR-Merge-Kennzahlen
PR-Kennzahlen ausstehend

Beschreibung

Crash report

What happened?

This one is a bit niche! It also needs a python compiled with --with-dtrace

probe.d:

python$target:::import-find-load-start
{
    printf("import probe fired\n");
}

test.py:

try:
  __import__('\ud800')
except:
  pass
> sudo dtrace -q -s probe.d -c './python.exe test.py'

Assertion failed: (!_PyErr_Occurred(tstate)), function _PyEval_EvalFrameDefault, file generated_cases.c.h, line 13858.
import probe fired
import probe fired
import probe fired
...

The import dtrace hooks pass call PyUnicode_AsUTF8 and pass the value to the probe without checking if the conversion succeeded, now dtrace doesn't seem to mind getting a null pointer (I don't know much about how that bit works tbh), but a stale exception is left around which triggers a debug assert:

https://github.com/python/cpython/blob/e8158d1a02d6e5e974d4dbc0633b6a3ad960d7a3/Python/import.c#L4106-L4107

[!CAUTION]
EDIT: I found some more cases of drace code doing the same, This isn't just limited to import machinery:
https://github.com/python/cpython/blob/91d71dd67074d4599b6bd49cc933f41f8bd57058/Python/ceval.c#L1198-L1225
If I find more, I'll add them

CPython versions tested on:

CPython main branch

Operating systems tested on:

macOS

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

Python 3.16.0a0 (heads/main:e8158d1a02d, Aug 20 2026, 15:09:24) [Clang 21.0.0 (clang-2100.3.27.1)]

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Baue Python mit --with-dtrace und reproduziere die Assertion anhand der Beispiele probe.d und test.py. Untersuche die Import-Hooks in Python/import.c und den zusätzlichen DTrace-Code in Python/ceval.c einschließlich der verknüpften Stellen. Erledigt ist die Aufgabe, wenn der Import eines einzelnen Surrogats keine veraltete Exception mehr hinterlässt und die Debug-Assertion nicht mehr auslöst, während das Probe aktiv ist.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

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

Neue Issues direkt in Ihr Postfach

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