python / python/cpython

crossinterp: Segfault in `check_missing___main___attr` if AttributeError args are not normal

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

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

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

説明

Crash report

What happened?

crossinterp doesn't do much checking on the arguments of the passed-in exception, allowing lone surrogate unicode, or non-str arguments cause segfaults:

Lone surrogate example:

from concurrent import interpreters
import __main__

x = 1

def f():
    return x  # forces pickle fallback

f.__name__ = f.__qualname__ = "\ud800"
setattr(__main__, "\ud800", f)

interp = interpreters.create()
interp.call(f)
> ./python.exe temp/crossinterp.py
fish: Job 1, './python.exe temp/crossinterp.py' terminated by signal SIGSEGV (Address boundary error)

Non-str argument example (a bit more convoluted):

from concurrent import interpreters

x = 1

def f():
    return x  # forces pickle fallback

interp = interpreters.create()
interp.exec("""
import pickle

def loads(data):
    raise AttributeError(42)

pickle.loads = loads
""")
interp.call(f)
> ./python.exe temp/crossinterp-2.py
fish: Job 1, './python.exe temp/crossinterp-2…' terminated by signal SIGSEGV (Address boundary error)

This is because check_missing___main___attr doesn't check the result of PyUnicode_AsUTF8 before passing it to strncmp, so if the object is not a PyUnicode object or if it can't be converted to utf8, you get a crash:

https://github.com/python/cpython/blob/91d71dd67074d4599b6bd49cc933f41f8bd57058/Python/crossinterp.c#L666-669

The fix should cover both cases, I guess:

A PyUnicode_Check on msgobj, and then a check that the PyUnicode_AsUTF8 return is valid.

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
  • gh-156128

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

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

はじめの一歩

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

調査の方向性

レポートで特定されているとおり、Python/crossinterp.c の check_missing___main___attr から始め、lone-surrogate を含む AttributeError のケースと、文字列ではない引数を持つ AttributeError のケースの両方を再現してください。不正な形式の例外引数によって segfault が発生しなくなったこと、および既存の cross-interpreter 呼び出しの動作がそのまま維持されていることを確認してください。gh-156128 はすでにこの issue にリンクされています。

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

評価

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

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

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