Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

`Base64Decoder` raises `DecodeError` on line-wrapped (MIME-style) base64

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

メンテナーはふだん 1 日以内に返信

@prudhvi1709 がすでに取り組んでいます。

2026年10月18日 から。

  • #341 @prudhvi1709 による — オープン

評価

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

調査の方向性

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 を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

Kludex/python-multipart のほかの issue

Kludex/python-multipart の issue をすべて見る

似ている issue

Python の issue をもっと見る

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

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