decimal: crash when a re-entrant __bool__ deallocates the Context during Context.flags assignment or comparison
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 77.2k
- フォーク
- 35.9k
- PR マージ指標
- PR 指標を取得中
説明
Bug report
Context.flags (and traps) is a SignalDict that borrows a pointer to
flags owned by its Context. signaldict_setitem and
signaldict_richcompare read that pointer after calling back into Python
(PyObject_IsTrue, i.e. the value's __bool__), which can deallocate the
Context. gh-146011 cleared the borrowed pointer on Context teardown and
guarded signaldict_repr, but these two methods were left unguarded, so the
same teardown leaves them dereferencing a NULL pointer and crashing.
Assignment:
import decimal, gc
ctx = decimal.Context()
flags = ctx.flags
class Evil:
def __bool__(self):
global ctx; del ctx; gc.collect()
return True
flags[decimal.InvalidOperation] = Evil() # segfault
Comparison:
import decimal, gc
ctx = decimal.Context()
other = ctx.flags.copy()
class Evil:
def __bool__(self):
global ctx; del ctx; gc.collect()
return True
other[decimal.InvalidOperation] = Evil()
ctx.flags == other # segfault
Both crash with SIGSEGV on current main; the affected code exists on 3.13+.
Linked PRs
- gh-155494
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
decimal モジュールのエントリポイント signaldict_setitem と signaldict_richcompare から始め、その後 Python 3.13+ で issue の代入および比較の例を再現します。Context の teardown 後に、両方の再入可能な bool ケースでクラッシュしなくなれば完了です。リンクされた PR gh-155494 がこの作業をすでにカバーしている点に注意してください。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- backend
- issue の種類
- バグ
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 停滞
- 明瞭さ
- 明確に書かれている
- 初心者へのやさしさ
- 25/100