gc.get_referrers() can be used to see objects before they are fully built
还没有人认领这个 Issue。
- 主要语言
- Python
- 星标
- 77.2k
- 派生
- 36k
- PR 合并指标
- PR 指标待抓取
描述
Crash report
That the problem is occurring in the Py_INCREF macro, it looks like that the error occurs because the code is trying to increment the reference count of an object that doesnt exist.
Steps to reproduce the behavior:
1.create a sample file that contains:
import gc
def g():
marker = object()
yield marker
[tup] = [x for x in gc.get_referrers(marker) if type(x) is tuple]
print(tup)
print(tup[1])
tuple(g())
- just run without opt:
./target/python/Python-3.11.1/builded/bin/python3.11 ./target/python/founded/sig11_sync_Python3111_52.py
Error messages
stderr:
(<object object at 0x7f9e66d10160>, <NULL>, <NULL>, <NULL>, <NULL>, <NULL>, <NULL>, <NULL>, <NULL>, <NULL>)
Segmentation fault (core dumped)
gdb:
After run with synthetical sample, binary file aborted with Segfault:
Program terminated with signal SIGSEGV, Segmentation fault.
#0 Py_INCREF (op=0x0) at ./Include/object.h:502
warning: Source file is more recent than executable.
502 #ifdef Py_REF_DEBUG
Expected behavior
No assertion failed.
Additional context
For solution this problem added additional checking to ensure that the op argument is not a null pointer before trying to increment its reference count.
if (op == NULL) {
return;
}
(also added in a patch)
Environment
- Tested on: Python 3.11.1
- Operating system and architecture: Centos-based system (RED OS release MUROM (7.3.2)) ; 5.15.78-2.el7.3.x86_64
Linked PRs
- gh-101856
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
使用 gc.get_referrers() 和 tuple(g()) 通过 Python 示例重现该问题,然后检查报告中所指 Py_INCREF 位置处的 Include/object.h。将观察到的 NULL 条目和 segmentation fault 与链接的 PR gh-101856 进行比较;当复现程序不再暴露无效的元组条目或发生崩溃时,即表示完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- c, python
- 领域
- compilers
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 25/100