crossinterp: Segfault in `check_missing___main___attr` if AttributeError args are not normal
還沒有人認領這個 Issue。
- 主要語言
- 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:
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
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
如報告所指出,從 Python/crossinterp.c 中的 check_missing___main___attr 開始,並重現 lone-surrogate 和 non-string AttributeError 案例。確認格式錯誤的例外引數不再導致 segmentation fault,且現有的 cross-interpreter 呼叫行為仍保持不變;gh-156128 已經連結至此 issue。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- c, python
- 領域
- backend
- Issue 類型
- 缺陷
- 難度
- 2/5
- 預估耗時
- 1-3 小時
- 活躍度
- 停滯
- 描述清晰度
- 描述清楚
- 新手友好度
- 35/100