PyMemoryView_FromBuffer discards owner reference from Py_buffer
還沒有人認領這個 Issue。
- 主要語言
- Python
- 星號
- 77.2k
- 分支
- 36k
- PR 合併指標
- PR 指標待擷取
描述
Bug report
Bug description:
This means that if you use PyMemoryView_FromBuffer with a buffer that requires an owner to be kept alive, you get a UAF hazard here.
This is not mentioned in the documentation: https://docs.python.org/3/c-api/memoryview.html#c.PyMemoryView_FromBuffer
An extremely cursory didn't find any vulnerable callers within CPython itself, however this was discovered in the process of implementing https://github.com/PyO3/pyo3/pull/5937 where it definitely would have been an issue.
It seems like there's two possible choices here:
- Change this to keep
owneraround -- potentially breaks existing callers? - Document this, and introduce a new API with clearer semantics here.
CPython versions tested on:
CPython main branch
Operating systems tested on:
No response
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
從 Objects/memoryobject.c 中連結的 PyMemoryView_FromBuffer 實作開始,並閱讀 PyMemoryView_FromBuffer C-API 文件。查看 PyO3 pull request #5937 以了解 owner 的生命週期要求,然後比較保留 owner 與引入新 API 對相容性的影響。完成的標準是決定並記錄 ownership 語義,且由適當的 CPython 測試涵蓋。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- c, python
- 領域
- api
- Issue 類型
- 缺陷
- 難度
- 5/5
- 預估耗時
- 一週以上
- 活躍度
- 冷清
- 描述清晰度
- 基本清楚
- 新手友好度
- 38/100