ShareableList corrupts multi-byte UTF-8 strings and bytes with trailing nulls
未关闭
还没有人认领这个 Issue。
stdlib
topic-multiprocessing
type-bug
- 主要语言
- Python
- 星标
- 77.2k
- 派生
- 35.9k
- PR 合并指标
- PR 指标待抓取
描述
Bug report
Bug description:
Issue
ShareableList allocates string slots based on character count instead of UTF-8 byte count, causing corruption for multi-byte characters. Additionally, rstrip(b'\x00') strips legitimate trailing null bytes from bytes values.
Note: The trailing null bytes issue was originally reported in #106939 (July 2023) and documented as a known issue with a workaround. This fix attempts to resolve both that long-standing issue and the newly discovered UTF-8 corruption bug.
Reproducer
from multiprocessing.shared_memory import ShareableList
# String corruption
sl = ShareableList(['0\U00010000\U00010000'])
print(sl[0]) # UnicodeDecodeError
sl.shm.close(); sl.shm.unlink()
# Bytes corruption
sl = ShareableList([b'\x00'])
print(repr(sl[0])) # b'' instead of b'\x00'
sl.shm.close(); sl.shm.unlink()
CPython versions tested on:
CPython main branch
Operating systems tested on:
No response
Linked PRs
- gh-145266
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 multiprocessing.shared_memory.ShareableList 入口开始,并运行 issue 中的两个复现代码片段。当多字节字符串仍可解码且 bytes 值保留末尾的 null 字节时,即表示完成;由于相关工作已经在进行,请在开始前查看关联的 PR gh-145266。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- operating-systems
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 描述清楚
- 新手友好度
- 25/100