python / python/cpython

ShareableList corrupts multi-byte UTF-8 strings and bytes with trailing nulls

未關閉
#145,261 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 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

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

研究方向

從 multiprocessing.shared_memory.ShareableList 進入點開始,並執行 issue 中的兩個重現程式片段。當多位元組字串仍可解碼,且 bytes 值保留結尾的 null 位元組時,即表示完成;由於相關工作已在進行,請在開始前檢視連結的 PR gh-145266。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
python
領域
operating-systems
Issue 類型
缺陷
難度
3/5
預估耗時
1-2 天
活躍度
停滯
描述清晰度
描述清楚
新手友好度
25/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。