Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

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

Aperta
#340 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@prudhvi1709 ci sta già lavorando.

Dal 18/10/2026.

  • #341 di @prudhvi1709 — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
25/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
python
Ambito
api

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
Python
Stelle
537
Fork
104
Merge medio
3h
PR unite (30g)
4

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di Kludex/python-multipart

Tutte le issue di Kludex/python-multipart

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.