Reject malformed Base64 padding in bytes loaders - #456
Open
gaoflow wants to merge 2 commits into
Open
Conversation
Author
|
The Coverage job failed before reading any coverage data: its first request, GET https://api.github.com/repos/reagento/adaptix, returned HTTP 503 with GitHub's Unicorn HTML page. All seven test jobs that produced the coverage artifacts passed. I attempted to rerun only the failed job, but fork contributors do not have the required repository permission. |
|
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.



Problem
The bytes-like loaders pre-check their input against the Base64 alphabet, but binascii.a2b_base64 is permissive about padding. Inputs made only of padding or carrying excess padding, such as =, AAA==, and AAAA=, are therefore accepted and silently decoded. Non-ASCII strings also leak UnicodeEncodeError instead of the loader error contract.
Fix
Validate that padding does not exceed the amount implied by the data length before decoding, while preserving the existing decoder errors for missing padding. Convert non-ASCII input to ValueLoadError consistently.
The shared bytes loader covers bytes, bytearray, BytesIO, and IO[bytes]. Regression coverage exercises all four through Retort across strict/lax coercion and every debug-trail mode, including empty and correctly padded boundary cases.
Validation