Repository navigation
dtrace: debug abort importing module with lone surrogate unicode char in name while DTrace import probe is active #156118
Copy link
Copy link
Open
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-crashA hard crash of the interpreter, possibly with a core dumpA hard crash of the interpreter, possibly with a core dump
Description
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:
Lines 4106 to 4107 in e8158d1
| if (PyDTrace_IMPORT_FIND_LOAD_START_ENABLED()) | |
| PyDTrace_IMPORT_FIND_LOAD_START(PyUnicode_AsUTF8(abs_name)); |
Caution
EDIT: I found some more cases of drace code doing the same, This isn't just limited to import machinery:
Lines 1198 to 1225 in 91d71dd
| dtrace_function_entry(_PyInterpreterFrame *frame) | |
| { | |
| const char *filename; | |
| const char *funcname; | |
| int lineno; | |
| PyCodeObject *code = _PyFrame_GetCode(frame); | |
| filename = PyUnicode_AsUTF8(code->co_filename); | |
| funcname = PyUnicode_AsUTF8(code->co_name); | |
| lineno = PyUnstable_InterpreterFrame_GetLine(frame); | |
| PyDTrace_FUNCTION_ENTRY(filename, funcname, lineno); | |
| } | |
| static void | |
| dtrace_function_return(_PyInterpreterFrame *frame) | |
| { | |
| const char *filename; | |
| const char *funcname; | |
| int lineno; | |
| PyCodeObject *code = _PyFrame_GetCode(frame); | |
| filename = PyUnicode_AsUTF8(code->co_filename); | |
| funcname = PyUnicode_AsUTF8(code->co_name); | |
| lineno = PyUnstable_InterpreterFrame_GetLine(frame); | |
| PyDTrace_FUNCTION_RETURN(filename, funcname, lineno); | |
| } |
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)]
Linked PRs
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-crashA hard crash of the interpreter, possibly with a core dumpA hard crash of the interpreter, possibly with a core dump
Activity