Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

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

Đang mở
#340 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@prudhvi1709 đang làm issue này rồi.

Từ ngày 18/10/2026.

  • #341 của @prudhvi1709 — đang mở

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
25/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
python
Lĩnh vực
api

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
Python
Star
537
Fork
104
Merge trung bình
3 giờ
Pull request đã merge (30 ngày)
4

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của Kludex/python-multipart

Tất cả issue của Kludex/python-multipart

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.