python / python/cpython

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

未关闭
#128,965 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

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. Fork 仓库,在一个分支上完成修改。
  4. 提交 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

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。