frameobject: undefined 32-bit left shifts in `stack_swap()`
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
The undefined shifts are in stack_swap() in Objects/frameobject.c, around line 1323, where MASK and top are shifted as 32-bit values. Read it alongside mark_stacks and frame_setlineno(), which call it. Run the reproducer under UBSan to see the shift warnings. Done means the shifts operate on 64-bit values and the sanitizer run is clean. The issue already links PR gh-161667, so check that before starting.
由索引模型根据 Issue 内容生成。
描述
Crash report
stack_swap() in Objects/frameobject.c shifted MASK and top as
32-bit values and converted the result to int64_t, while the value-stack
model is a 63-bit int64_t and shift = BITS_PER_BLOCK*(n-1) can reach 60.
The shifts overflow / drop bits (undefined behavior) and corrupt the stack
model used by frame_setlineno() to validate line jumps.
import dis
import sys
fors = " ".join(f"for v{i} in range(1)" for i in range(11))
ns = {}
exec(f"def f():\n return [0 {fors}]\n", ns)
f = ns["f"]
triggered = False
def tracer(frame, event, arg):
global triggered
if event == "line" and frame.f_code is f.__code__ and not triggered:
triggered = True
frame.f_lineno = frame.f_lineno # mark_stacks -> stack_swap
return tracer
sys.settrace(tracer)
try:
f()
finally:
sys.settrace(None)
UBSan output:
Objects/frameobject.c:1323:44: runtime error: shift exponent 33 is too large for 32-bit type 'int'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Objects/frameobject.c:1323:44 in
Objects/frameobject.c:1323:62: runtime error: shift exponent 33 is too large for 32-bit type 'unsigned int'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Objects/frameobject.c:1323:62 in
Found by Linux Verification Center (linuxtesting.org) with SVACE
CPython versions tested on:
CPython main branch
Operating systems tested on:
No response
Output from running 'python -VV' on the command line:
No response
Linked PRs
- gh-161667
- 主要语言
- Python
- 星标
- 78.2k
- 派生
- 36.6k
- 平均合并
- 19 小时 57 分钟
- 30 天内合并 PR
- 630
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
python/cpython 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
stdlib type-bug
难度 2/5 1-3 小时 新手友好度 75/100
维护者通常 1 天内回复
-
extension-modules stdlib topic-XML type-bug
难度 2/5 1-3 小时 新手友好度 76/100
python/cpython#161807 · 1 条评论 ·
维护者通常 1 天内回复
-
stdlib type-feature
难度 2/5 1-3 小时 新手友好度 78/100
python/cpython#161788 · 7 条评论 ·
维护者通常 1 天内回复
-
extension-modules topic-IO type-bug
难度 2/5 1-3 小时 新手友好度 75/100
维护者通常 1 天内回复
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 62/100
cpp-best-practices/project_validator#267 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
Project-N-E-K-O/N.E.K.O#3725 ·
维护者通常 1 天内回复
-
[Bug] Sending a Telegram message chain twice duplicates mentions可能已有人在做 @123XieC 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 72/100
AstrBotDevs/AstrBot#11125 ·
维护者通常 1 天内回复
-
backend bug priority: high
难度 2/5 1-3 小时 新手友好度 72/100
nooriegarg/ContribIQ#73 ·
维护者通常 1 天内回复
-
bug p3 security
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 1 天内回复