python / python/cpython

pickle `load_build` function checks if `state` is None, not False

オープン
#128,965 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

stdlib type-bug
主要言語
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/Modules/_pickle.c#L6638

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

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

Lib/pickle.py と Modules/_pickle.c の BUILD の処理を、提供された b']]b.' バイトストリームとその逆アセンブル結果から調べて比較してください。異なる動作を再現し、既存の pickle のテストカバレッジを確認してください。両方の実装が false-y の状態値を、報告されたエラーなしで一貫して処理できれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
backend
issue の種類
バグ
難易度
2/5
見積もり時間
1〜3時間
活発さ
停滞
明瞭さ
明確に書かれている
初心者へのやさしさ
25/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。