array: unpickling an odd-length 'w' array across endianness raises ValueError (wrong UTF-16/UTF-32 item size)
还没有人认领这个 Issue。
- 主要语言
- Python
- 星标
- 77.2k
- 派生
- 36k
- PR 合并指标
- PR 指标待抓取
描述
Bug report
array.array pickles carry a machine-format code so the receiver can decode
data from a different platform. The decoder's format table
(mformat_descriptors in Modules/arraymodule.c) stores a wrong item size
for the Unicode formats: UTF-16 entries say 4 bytes per item (actual: 2) and
UTF-32 entries say 8 (actual: 4).
The only consumer of that field is the length check on the cross-endian slow
path, so unpickling an odd-length 'w' array from a machine of the opposite
endianness fails:
import array
recon = array._array_reconstructor # what pickle calls
data = 'abc'.encode('utf-32-be') # 3 code points, big-endian
recon(array.array, 'w', 21, data) # 21 = UTF32_BE, on a little-endian machine
# ValueError: string length not a multiple of item size
Even lengths decode correctly, and same-endian pickles use the fast path that
skips the check, which is why this stayed hidden. On 3.13/3.14 the 'u'
typecode maps to the (equally wrong) UTF-16 entries on Windows.
Linked PRs
- gh-155851
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 Modules/arraymodule.c 开始,重点检查 mformat_descriptors 表和 _array_reconstructor 的跨端序路径。验证奇数长度的 UTF-16 和 UTF-32“w”或“u”数据能否跨端序进行 unpickle,而不会出现 item-size ValueError;链接的 PR gh-155851 表明这项工作已经在进行中。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- c, python
- 领域
- backend
- Issue 类型
- 缺陷
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 活跃度
- 停滞
- 描述清晰度
- 描述清楚
- 新手友好度
- 25/100