pickle `load_build` function checks if `state` is None, not False
還沒有人認領這個 Issue。
- 主要語言
- Python
- 星號
- 77.2k
- 分支
- 35.9k
- PR 合併指標
- PR 指標待擷取
描述
Bug report
Bug description:
Inside of the load_build() function for pickle's BUILD opcode, the C accelerator at one point checks if state is Py_None, while the Python version only checks if state.
https://github.com/python/cpython/blob/34ded1a1a10204635cad27830fcbee2f8547e8ed/Lib/pickle.py#L1765
This means if state is something like an empty dictionary or tuple, the code block under the if statement WILL be run in _pickle.c, but NOT in pickle.py.
As an example, the bytestream b']]b.' has the following disassembly:
0: ] EMPTY_LIST
1: ] EMPTY_LIST
2: b BUILD
3: . STOP
highest protocol among opcodes = 1
This will do nothing in pickle.py but error out in _pickle.c with the message state is not a dictionary. The easy solution is to change if state to if state != None, and it shouldn't break any existing functionality. I've attached a pull request.
CPython versions tested on:
3.11
Operating systems tested on:
Linux
Linked PRs
- gh-128966
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
比較 Lib/pickle.py 和 Modules/_pickle.c 中對 BUILD 的處理,從提供的 b']]b.' 位元組串流及其反組譯結果開始。重現兩者不同的行為,並檢查現有的 pickle 測試涵蓋率;當兩個實作都能在不出現回報錯誤的情況下,一致地處理 false-y 狀態值時,即表示完成。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- python
- 領域
- backend
- Issue 類型
- 缺陷
- 難度
- 2/5
- 預估耗時
- 1-3 小時
- 活躍度
- 停滯
- 描述清晰度
- 描述清楚
- 新手友好度
- 25/100