python / python/cpython

`super.__new__(super)` can create an object that causes a NULL dereference in supercheck()

未关闭
#155,376 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

interpreter-core type-crash
主要语言
Python
星标
77.2k
派生
35.9k
PR 合并指标
PR 指标待抓取

描述

Crash report

What happened?

super.__new__(super) can create a super object whose internal type field is NULL. Using that object as a descriptor then causes a segmentation fault in supercheck().

Minimal reproducer:

s = super.__new__(super)
print(s)
s.__get__(1)

Output:

<super: <class 'NULL'>, NULL>
Segmentation fault (core dumped)

The one-line form also reproduces the crash:

super.__new__(super).__get__(1)

This is deterministic on the tested build.

A normal initialized super object does not crash:

class A:
    pass

class B(A):
    pass

s = super(B, B())
print(s.__get__(B()))

Output:

<super: <class 'B'>, ...>

GDB confirms the NULL dereference:

Program received signal SIGSEGV, Segmentation fault.
supercheck (type=0x0, obj=...)
    at Objects/typeobject.c:12605

The crashing code is:

PyErr_Format(PyExc_TypeError,
            "super(type, obj): obj (%s %.200s) is not "
            "an instance or subtype of type (%.200s).",
            type_or_instance, obj_str, type->tp_name);

Here type == NULL, so evaluating type->tp_name dereferences NULL.

The relevant call path is:

super.__new__(super)
    -> PyType_GenericNew()
    -> uninitialized super object (su->type == NULL)
    -> super_descr_get()
    -> supercheck(su->type, obj)
    -> type->tp_name
    -> SIGSEGV

PySuper_Type currently uses PyType_GenericNew as its tp_new, while initialization of the internal fields is performed separately by super_init. Therefore direct use of super.__new__(super) bypasses that initialization.

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Output from running 'python -VV' on the command line:

Python 3.16.0a0 (heads/audit-objects-phase1-dirty:c3aefdb9eff, Aug 7 2026, 19:38:01) [GCC 13.3.0]

Linked PRs
  • gh-155379

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从 Objects/typeobject.c 中的 supercheck() 开始,然后跟踪 PySuper_Type 的 PyType_GenericNew,以及报告中描述的独立 super_init 路径。使用 super.new(super).get(1) 的复现程序作为回归覆盖;完成的标准是它不再崩溃,而是报告适当的错误。

由索引模型根据 Issue 内容生成。

评估

技术栈
c, python
领域
backend
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
描述清楚
新手友好度
25/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。