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 的 AttributeError 情况,以及带有非字符串参数的 AttributeError 情况。验证格式错误的异常参数不再导致 segfault,并确认现有的 cross-interpreter 调用行为保持不变;gh-156128 已经关联到此 issue。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- c, python
- 领域
- backend
- Issue 类型
- 缺陷
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 活跃度
- 停滞
- 描述清晰度
- 描述清楚
- 新手友好度
- 35/100