decimal: crash when a re-entrant __bool__ deallocates the Context during Context.flags assignment or comparison
還沒有人認領這個 Issue。
- 主要語言
- Python
- 星號
- 77.2k
- 分支
- 36k
- 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 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 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