Repository navigation
Reject non-ASCII chars in Base64.DecodeFromChars - #641
Merged
Merged
Conversation
This was referenced Oct 12, 2026
This was referenced Oct 13, 2026
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.
Bug
The
OperationStatusoverload of theBase64.DecodeFromCharspolyfill copied the input into a UTF-8 buffer with(byte) source[i]. A non-ASCII char was narrowed to its low byte, which can be a valid base-64 character, so invalid input decoded successfully:"AQI\u0144"(U+0144narrows to'D') returnedDonewith the bytes of"AQID". The BCL returnsInvalidDatawith 0 consumed and 0 written. (In acheckedconsumer build the same cast threwOverflowException.)Fix
Chars above
0x7Fare mapped to0xFF, which is never a valid base-64 byte, soBase64.DecodeFromUtf8reportsInvalidDataat the right position.Test
Base64Tests.DecodeFromChars_OperationStatus_NonAsciicovers a non-ASCII char at the end of the first quantum, at the start, and in the second quantum (asserting 4 consumed / 3 written). It fails withDonebefore the fix on net48. AllBase64Testspass on net48 and net8.0 (polyfill) and net11.0 (BCL).