iconv codecs write an error handler's replacement in a non-initial shift state
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 77.2k
- フォーク
- 35.9k
- PR マージ指標
- PR 指標を取得中
説明
Bug report
An error handler's replacement bytes are copied to the output without returning it to the initial shift state first, so in a stateful encoding they are read back as encoded data.
>>> '中😀中'.encode('iso-2022-cn', 'replace')
b'\x1b$)A\x0eVP?\x1b$)A\x0eVP\x0f'
>>> _.decode('iso-2022-cn')
UnicodeDecodeError: 'iso-2022-cn' codec can't decode byte 0x3f in position 7: invalid multibyte sequence
>>> '中😀中'.encode('iso-2022-cn', 'backslashreplace').decode('iso-2022-cn')
'中苷鞍氨娑鞍中'
The built-in codec of the same family shifts back to ASCII first:
>>> '日😀日'.encode('iso2022_jp', 'replace') # built-in
b'\x1b$BF|\x1b(B?\x1b$BF|\x1b(B'
>>> '日😀日'.encode('iconv:ISO-2022-JP', 'replace') # iconv
b'\x1b$BF|?\x1b$BF|\x1b(B'
_PyUnicode_EncodeIconv() does reset the shift state after each handled error, but with a NULL output buffer, so the conversion forgets the state while the stream never gets the closing sequence.
This affects the ISO-2022 family and the stateful EBCDIC code pages (CP1364, CP1371, ...). ignore is unaffected, it injects nothing.
Linked PRs
- gh-155005
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
_PyUnicode_EncodeIconv() のエントリポイントから開始し、レポートにある ISO-2022 および状態を持つ EBCDIC の例を再現してください。置換バイトの出力とデコードを組み込みの ISO-2022-JP の動作と比較します。処理された置換が初期の shift 状態に戻り、ignore は影響を受けないことが完了条件です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- internationalization
- issue の種類
- バグ
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100