Skip to content

fix(multipart): ensure BodyPartReader.read() returns bytes not bytearray#12412

Closed
armorbreak001 wants to merge 1 commit intoaio-libs:masterfrom
armorbreak001:fix/multipart-bytearray-leak
Closed

fix(multipart): ensure BodyPartReader.read() returns bytes not bytearray#12412
armorbreak001 wants to merge 1 commit intoaio-libs:masterfrom
armorbreak001:fix/multipart-bytearray-leak

Conversation

@armorbreak001
Copy link
Copy Markdown

Summary

BodyPartReader.read() accumulates data in an internal bytearray buffer but returns it directly without converting to bytes. This violates the documented return type annotation (bytes) and causes TypeError in downstream code that passes the result to json.dumps() or any API expecting bytes rather than bytearray.

The fix wraps both return paths with bytes() so the returned type always matches the annotation.

Fixes #12404

The read() method accumulated data in a bytearray but returned it
directly, violating the documented return type annotation (bytes).
This caused TypeError when passing the result to json.dumps or
other APIs that expect bytes rather than bytearray.
@armorbreak001 armorbreak001 requested a review from asvetlov as a code owner April 22, 2026 14:06
@armorbreak001
Copy link
Copy Markdown
Author

Duplicate of #1249 (already open, fixes same issue #12404).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: BodyPartReader.filename and read() leak bytearray instead of str/bytes, violating API contract and breaking JSON serialization

2 participants