python / python/cpython

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

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

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

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. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

エントリーポイント multiprocessing.shared_memory.ShareableList から始め、issue にある 2 つの再現スニペットを実行してください。マルチバイト文字列が引き続きデコード可能であり、bytes 値が末尾の null バイトを保持すれば完了です。作業はすでに進行中のため、開始前にリンク先の PR gh-145266 を確認してください。

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

評価

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

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

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