cap base64 body-part reads at the declared Content-Length - #13497
Closed
arshsmith1 wants to merge 2 commits into
Closed
cap base64 body-part reads at the declared Content-Length#13497arshsmith1 wants to merge 2 commits into
arshsmith1 wants to merge 2 commits into
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #13497 +/- ##
=======================================
Coverage 99.00% 99.00%
=======================================
Files 132 132
Lines 49635 49651 +16
Branches 2575 2577 +2
=======================================
+ Hits 49141 49158 +17
Misses 370 370
+ Partials 124 123 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. |
Merging this PR will not alter performance
Comparing Footnotes
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What do these changes do?
BodyPartReader.read_chunkpads base64 body-part data out to whole 4-byte groups by topping up from the stream. For a length-delimited part (one carryingContent-Length, e.g. insidemultipart/mixed) that top-up read went straight toself._content.read()with no bound, so when a part's whitespace-stripped base64 length is not a multiple of 4 it reads past the declared length into the trailing CRLF, the boundary and the parts that follow. A part sent withContent-Length: 19comes back as 75 bytes carrying a later part's data, and once_read_bytesovershoots_lengtha subsequent read can pass a negative size toStreamReader.readand drain the rest of the stream. The top-up read is now capped at the bytes still owed by the declared part length, so a length-delimited part stops at its boundary.Are there changes in behavior for the user?
Only for the malformed case. A base64 part whose declared length is a proper multiple of 4 (including CRLF-wrapped bodies) reads and decodes exactly as before across chunk sizes; a part that previously over-read now returns just its declared bytes and reaches EOF at the boundary instead of pulling in the following parts.
Is it a substantial burden for the maintainers to support this?
No. It bounds one existing read by the part length the reader already tracks.
Related issue number
None.
Checklist
CONTRIBUTORS.txt(already listed)CHANGES/folder