`Base64Decoder` raises `DecodeError` on line-wrapped (MIME-style) base64
メンテナーはふだん 1 日以内に返信
評価
調査の方向性
Start by reading Base64Decoder.write() and reproduce the failure with the provided CRLF example, then try split writes and base64.encodebytes data in small chunks. A regression test should show that MIME-wrapped input decodes to the expected bytes regardless of line breaks or chunk boundaries; pull request #341 already submits a fix.
索引モデルが issue の本文から書いたものです。
説明
Base64Decoder.write() slices the input to a multiple of 4 bytes before decoding, but it counts line breaks and spaces as base64 characters. Standard base64 as used in MIME (RFC 2045) is wrapped with CRLF or LF, so any quartet that straddles a line break is miscounted and decoding fails. The result also depends on how the stream is chunked.
Reproduction
from io import BytesIO
from python_multipart.decoders import Base64Decoder
out = BytesIO()
d = Base64Decoder(out)
d.write(b"Zm9v\r\nYmFy") # DecodeError
d.finalize()
Expected: b"foobar", which is what base64.b64decode(b"Zm9v\r\nYmFy") returns.
Split writes fail the same way:
d.write(b"Zm9v\r")
d.write(b"\nYmFy") # DecodeError
base64.encodebytes(bytes(range(200))) (76-character lines) written in chunks of 10, 7 or 1 bytes also raises DecodeError.
Cause
write() computes decode_len = (len(data) // 4) * 4 on data that still contains \r, \n, space and tab. b64decode() then discards those bytes (it is not called with validate=True), leaving a slice that is not a multiple of 4, and raises "Incorrect padding".
Version: python-multipart 0.0.32, main at 51ff1a4, Python 3.13.
Fix
A fix with a regression test is submitted in #341.
- 主要言語
- Python
- スター
- 537
- フォーク
- 104
- 平均マージ
- 3時間
- マージ済み PR(30日)
- 4
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
Kludex/python-multipart のほかの issue
-
Add streaming field limits to `FormParser`対応中かも @Kludex が 20 日前に担当しました。 オープン
難易度 4/5 3〜5日 初心者へのやさしさ 30/100
Kludex/python-multipart#332 ·
メンテナーはふだん 1 日以内に返信
-
Clarify or handle non-Latin-1 str input in parse_options_header対応中かも @gyanu2507 が 62 日前に担当しました。 オープン
難易度 4/5 3〜5日 初心者へのやさしさ 42/100
Kludex/python-multipart#319 ·
メンテナーはふだん 1 日以内に返信
-
How to set FormParser MAX_BODY_SIZE, MAX_MEMORY_FILE_SIZE?対応中かも @dokson が 139 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 35/100
Kludex/python-multipart#201 · コメント 1 件 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信
-
Skip header area?対応中かも @Kludex が 197 日前に担当しました。 オープン
難易度 3/5 1〜2日 初心者へのやさしさ 48/100
Kludex/python-multipart#59 · コメント 3 件 ·
メンテナーはふだん 1 日以内に返信
-
Failing to parse non-standard line breaks対応中かも @dokson が 139 日前に担当しました。 オープン
難易度 4/5 3〜5日 初心者へのやさしさ 32/100
Kludex/python-multipart#31 · コメント 4 件 · リアクション 4 件 ·
メンテナーはふだん 1 日以内に返信
Kludex/python-multipart の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
メンテナーはふだん 1 日以内に返信
-
enhancement good first issue
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
iceboundrock/AutoForge#304 ·
メンテナーはふだん 1 日以内に返信
-
enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
fossasia/visdom-dev#77 ·
メンテナーはふだん 4 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
aws-cloudformation/cfn-lint#4890 ·
メンテナーはふだん 2 日以内に返信