Skip to content

Throw FormatException from Base64.TryDecodeFromChars for invalid input - #634

Merged
SimonCropp merged 3 commits into
mainfrom
fix/base64-trydecodefromchars-throws
Oct 11, 2026
Merged

SimonCropp merged 3 commits into
mainfrom
fix/base64-trydecodefromchars-throws

Conversation

@SimonCropp

Copy link
Copy Markdown
Owner

Bug

The Base64.TryDecodeFromChars polyfill caught FormatException and returned false for invalid input. The net11 BCL only returns false when the destination is too small; invalid input ("!!!!", "AQI", "AQ=I") throws FormatException. Callers could not tell a too-small buffer from bad data, and code written against the polyfill changed behaviour on net11.

Fix

Remove the try/catch so the FormatException propagates.

Test

Base64Tests.TryDecodeFromChars_Invalid asserts the exception for three invalid inputs and TryDecodeFromChars_TooSmall pins the false path. 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 force-pushed the fix/base64-trydecodefromchars-throws branch from a2826c0 to f35a680 Compare October 11, 2026 23:17
@SimonCropp
SimonCropp merged commit bd49cec into main Oct 11, 2026
@SimonCropp
SimonCropp deleted the fix/base64-trydecodefromchars-throws branch October 11, 2026 23:39
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.

2 participants