python / python/cpython

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

オープン
#156,114 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

interpreter-core type-crash
主要言語
Python
スター
77.2k
フォーク
35.9k
PR マージ指標
PR 指標を取得中

説明

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

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

Python/perf_trampoline.c の perf_map_write_entry から始め、perf_jit_trampoline が使用する共有ヘルパーと変換処理を比較してください。lone surrogate を含むファイル名の例で報告を再現し、その後、変換失敗によって stale exception が残ったり abort が発生したりしないことを確認してください。リンクされた PR は、この作業がすでに進行中であることを示しています。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
c, python
領域
operating-systems, performance
issue の種類
バグ
難易度
2/5
見積もり時間
1〜3時間
活発さ
停滞
明瞭さ
明確に書かれている
初心者へのやさしさ
25/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。