sqlite3: NULL pointer dereference in window aggregate xValue/xInverse callbacks when the window frame is empty
まだ誰も着手していません。
- 主要言語
- 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 にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
Modules/_sqlite/connection.c から始め、特に value_callback と inverse_callback のパスを確認し、付属のウィンドウ関数の再現プログラムを標準ビルドとデバッグビルドに対して実行してください。空のフレームのケースが SIGSEGV やアサーション失敗なしに完了すれば完了です。リンクされた PR gh-154576 は、すでに作業が進行中である可能性を示しています。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python, sqlite
- 領域
- databases
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 30/100