Unexpected nested exception with b64decode
オープン
まだ誰も着手していません。
docs
stdlib
- 主要言語
- Python
- スター
- 77.2k
- フォーク
- 35.9k
- PR マージ指標
- PR 指標を取得中
説明
Bug report
Bug description:
The b64decode function of the base64 standard library module can behave in unexpected ways with invalid inputs.
Take this example:
#!/usr/bin/python3
import base64
base64.b64decode('a\xd6==')
According to the docs, I would expect that invalid characters in the input cause a binascii.Error exception. However, this example gives me the following:
Traceback (most recent call last):
File "/usr/lib/python3.12/base64.py", line 37, in _bytes_from_decode_data
return s.encode('ascii')
^^^^^^^^^^^^^^^^^
UnicodeEncodeError: 'ascii' codec can't encode character '\xd6' in position 1: ordinal not in range(128)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/tmp/./test", line 3, in <module>
base64.b64decode('a\xd6==')
File "/usr/lib/python3.12/base64.py", line 83, in b64decode
s = _bytes_from_decode_data(s)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/base64.py", line 39, in _bytes_from_decode_data
raise ValueError('string argument should contain only ASCII characters')
ValueError: string argument should contain only ASCII characters
So not only do I get an exception that I don't expect according to the docs, it appears there is a bug in the internal exception handling causing an exception (ValueError) during another exception (UnicodeEncodeError).
CPython versions tested on:
3.13
Operating systems tested on:
Linux
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
非ASCII入力の例を再現し、その後 base64.py の b64decode と _bytes_from_decode_data の周辺を読んで、観測された例外と文書化された動作を比較します。無効な入力が、予期しない入れ子になった traceback なしに、文書化された例外の動作に従えば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- backend
- issue の種類
- バグ
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 45/100