python / python/cpython

segfault/debug abort from `perf_map_write_entry` with lone surrogate in filename or qualname

Open
#156,114 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?
import sys
import sysconfig
import types

assert not sysconfig.get_config_var("PY_HAVE_PERF_TRAMPOLINE")
sys.activate_stack_trampoline("perf")
code = compile("pass", "bad\ud800file", "exec")
eval(code)
python3: Python/generated_cases.c.h:13862: PyObject *_PyEval_EvalFrameDefault(PyThreadState *, _PyInterpreterFrame *, int): Assertion `!_PyErr_Occurred(tstate)' failed.
Aborted

perf_map_write_entry does not check that the calls to PyUnicde_AsUTF8 succeed, resulting in null pointers being passed to snprintf. This is UB, and may crash in some libc versions, or may be replaced with a placeholder value.

Regardless, a failed conversion leaves a stale exception around, which then will trigger a debug abort a bit later (in debug builds):

https://github.com/python/cpython/blob/e8158d1a02d6e5e974d4dbc0633b6a3ad960d7a3/Python/perf_trampoline.c#L251-L262

Seems trivial to check the result value here. I notice that perf_jit_trampoline (similar code) uses a common helper function that checks the values and replaces them with "" if NULL

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/main-dirty:20e6c2f, Aug 19 2026, 15:22:30) [Clang 22.1.8 ]

Linked PRs
  • gh-156300
  • gh-157773
  • gh-157774

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

Start in Python/perf_trampoline.c at perf_map_write_entry and compare its conversion handling with the shared helper used by perf_jit_trampoline. Reproduce the report with the lone-surrogate filename example, then verify that the conversion failure no longer leaves a stale exception or causes an abort; linked PRs indicate this work is already underway.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, python
Domain
operating-systems, performance
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.