sqlite3 Cursor NULL-deref via reentrant execute() inside a text_factory/converter during fetch
オープン
まだ誰も着手していません。
extension-modules
topic-sqlite3
type-bug
- 主要言語
- Python
- スター
- 77.2k
- フォーク
- 35.9k
- PR マージ指標
- PR 指標を取得中
説明
Bug report
Bug description:
import sqlite3
con = sqlite3.connect(":memory:")
con.execute("CREATE TABLE t(a TEXT, b TEXT)")
con.execute("INSERT INTO t VALUES ('first', 'second')")
cur = con.cursor()
def btf(data):
try:
cur.execute("SELECT 1")
except sqlite3.ProgrammingError:
pass
return bytes(data).decode()
con.text_factory = btf
cur.execute("SELECT a, b FROM t")
print(cur.fetchone())
Modules/_sqlite/cursor.c:402:23: runtime error: member access within null pointer of type 'struct pysqlite_Statement'
#0 _pysqlite_fetch_one_row Modules/_sqlite/cursor.c:402
#1 pysqlite_cursor_iternext Modules/_sqlite/cursor.c:1155
#2 pysqlite_cursor_fetchone_impl Modules/_sqlite/cursor.c:1206
#3 pysqlite_cursor_fetchone Modules/_sqlite/clinic/cursor.c.h:169
CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux
Linked PRs
- gh-157578
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
Modules/_sqlite/cursor.c、特に 402 行目付近の _pysqlite_fetch_one_row から始め、示されている text_factory コールバックを使って sanitizer 下で報告を再現します。フェッチ中に再入可能な cur.execute() がステートメントにどのような影響を与えるかを追跡します。完了の条件は、再現プログラムが NULL デリファレンスに到達しなくなり、既存の関連する作業と併せて適切なカバレッジが追加されることです。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python, sqlite
- 領域
- databases
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- 明確に書かれている
- 初心者へのやさしさ
- 30/100