sqlite3: NULL pointer dereference in window aggregate xValue/xInverse callbacks when the window frame is empty
还没有人认领这个 Issue。
- 主要语言
- Python
- 星标
- 77.2k
- 派生
- 35.9k
- PR 合并指标
- PR 指标待抓取
描述
Crash report
What happened?
This issue is a result review security advisories GHSA-g74h-5v93-4q3p.
Summary
Modules/_sqlite/connection.c in the sqlite3 standard library module
dereferences a NULL pointer when a user-defined aggregate window
function's value() (or inverse()) method is invoked by SQLite before
step() has ever been called for that window instance. This happens
whenever the window frame is empty for a given output row (e.g. the
first row of a partition with a frame such as
ROWS BETWEEN 1 PRECEDING AND 1 PRECEDING). On a standard (non-debug)
build, this crashes the whole Python process with SIGSEGV.
The problem in the code was found by the Svace static analyzer (ISP RAS) and
was later confirmed by a real REPL crash.
Details
Tested on: CPython 3.12.10 (Fedora 40 system build, standard release
build) and CPython main @ https://github.com/python/cpython/commit/4c79929705eb31959a6f4071cc34583de0737a28
(2026-07-06). No special configuration is needed - a default build of
either version reproduces this.
import sqlite3
class A:
def value(self):
return 1
con = sqlite3.connect(":memory:")
con.create_window_function("f", 1, A)
con.execute("CREATE TABLE t(x)")
con.execute("INSERT INTO t VALUES (1)")
con.execute(
"SELECT f(x) OVER (ROWS BETWEEN 1 PRECEDING AND 1 PRECEDING) FROM t"
).fetchall()
Result:
segmentation fault (core dumped) python
No step, inverse, or finalize method needs to be defined on A -
the single row's window frame is unconditionally empty (there is no
row "1 preceding" the only row in the table), so value() is the first
and only callback SQLite invokes.
For a debug build (Py_DEBUG=1, configure --with-pydebug), the
assert(*cls != NULL) fires instead of segfaulting, printing:
Assertion '*cls != NULL' failed in value_callback.
Package: sqlite3 C API.
Affected versions: >= 3.11
CPython versions tested on:
CPython main branch, 3.11, 3.12, 3.13, 3.14, 3.15, 3.16
Operating systems tested on:
Linux
Output from running 'python -VV' on the command line:
No response
Linked PRs
- gh-154576
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 Modules/_sqlite/connection.c 开始,特别检查 value_callback 和 inverse_callback 路径,并针对标准构建和调试构建运行随附的窗口函数复现程序。空 frame 情况在没有 SIGSEGV 或断言失败的情况下完成,即视为完成;关联的 PR gh-154576 表明相关工作可能已经在进行中。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python, sqlite
- 领域
- databases
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 30/100