python / python/cpython

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

Open
#156,118 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

interpreter-core type-crash
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

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:

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)]

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Build Python with --with-dtrace and reproduce the assertion using the probe.d and test.py examples. Inspect the import hooks in Python/import.c and the additional DTrace code in Python/ceval.c, including the linked locations. Done means the lone-surrogate import no longer leaves a stale exception or triggers the debug assertion while the probe is active.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
observability
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
50/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.