reject 0xFF byte in BASE64DecoderStream conversion table#206
Open
arib06 wants to merge 1 commit into
Open
Conversation
Signed-off-by: mohammed arib <arib@bugqore.com>
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.
BASE64DecoderStream fills a 256-entry lookup table that maps each input byte to its base64 value or to -1 for anything outside the alphabet, but the init loop stops at index 254 and leaves the last slot at its default of 0. A 0xFF byte therefore resolves to 0 rather than -1, so getByte treats it as the base64 character A and feeds it into the decoder instead of skipping it the way it skips every other non-alphabet byte. The encoded bytes come straight from untrusted message content, so an attacker can drop a 0xFF into an otherwise valid base64 body part and shift the four-character grouping, which either corrupts the decoded output or raises a DecodingException on input that a conformant decoder accepts. I noticed it while comparing decoder output against java.util.Base64, which ignores the same byte and decodes cleanly. Extending the loop to cover the whole table maps 0xFF to -1 so it is skipped like any other stray byte. The regression test decodes a stream with an injected 0xFF and checks the result matches both the clean stream and the JDK MIME decoder.