Skip to content

Reject non-ASCII chars in Base64.DecodeFromChars - #641

Merged
SimonCropp merged 1 commit into
mainfrom
fix/base64-decodefromchars-non-ascii
Oct 11, 2026
Merged

SimonCropp merged 1 commit into
mainfrom
fix/base64-decodefromchars-non-ascii

Conversation

@SimonCropp

Copy link
Copy Markdown
Owner

Bug

The OperationStatus overload of the Base64.DecodeFromChars polyfill 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+0144 narrows to 'D') returned Done with the bytes of "AQID". The BCL returns InvalidData with 0 consumed and 0 written. (In a checked consumer build the same cast threw OverflowException.)

Fix

Chars above 0x7F are mapped to 0xFF, which is never a valid base-64 byte, so Base64.DecodeFromUtf8 reports InvalidData at the right position.

Test

Base64Tests.DecodeFromChars_OperationStatus_NonAscii covers 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 with Done before the fix on net48. All Base64Tests pass on net48 and net8.0 (polyfill) and net11.0 (BCL).

@SimonCropp SimonCropp added this to the 11.4.4 milestone Oct 11, 2026
@SimonCropp
SimonCropp merged commit 71d8ce6 into main Oct 11, 2026
5 checks passed
@SimonCropp
SimonCropp deleted the fix/base64-decodefromchars-non-ascii branch October 11, 2026 22:11
This was referenced Oct 12, 2026
This was referenced Oct 13, 2026
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.

1 participant