Skip to content

#124513 - Guard Base64Url.DecodeFromChars against non-ASCII input#124540

Merged
tannergooding merged 6 commits intodotnet:mainfrom
Tomius:patch-1
Feb 19, 2026
Merged

#124513 - Guard Base64Url.DecodeFromChars against non-ASCII input#124540
tannergooding merged 6 commits intodotnet:mainfrom
Tomius:patch-1

Conversation

@Tomius
Copy link
Contributor

@Tomius Tomius commented Feb 18, 2026

Base64Url.DecodeFromChars in Microsoft.Bcl.Memory has an out-of-bounds read bug: DecodeFrom uses Unsafe.Add with raw char values as indices into a 256-element DecodingMap without checking the DecodeRemaining return value first. Non-ASCII chars (value > ~2048) cause an AccessViolationException on .NET 8.

Workaround: Add System.Text.Ascii.IsValid check before decoding to reject non-ASCII input early. Base64/Base64Url only uses ASCII characters, so any non-ASCII input is inherently invalid.

Fixes #124513

dotnet#124513 - Guard Base64Url.DecodeFromChars against non-ASCII input

Base64Url.DecodeFromChars in Microsoft.Bcl.Memory has an out-of-bounds read bug: DecodeFrom uses Unsafe.Add with raw char values as indices into a 256-element DecodingMap without checking the DecodeRemaining return value first. Non-ASCII chars (value > ~2048) cause an AccessViolationException on .NET 8.

Workaround: Add System.Text.Ascii.IsValid check before decoding to reject non-ASCII input early. Base64/Base64Url only uses ASCII characters, so any non-ASCII input is inherently invalid.

See: dotnet#124513
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Feb 18, 2026
@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-system-buffers
See info in area-owners.md if you want to be subscribed.

Copy link
Member

@tannergooding tannergooding left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks!

Copy link
Member

@jeffhandley jeffhandley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM too. Thanks!

Copy link
Member

@GrabYourPitchforks GrabYourPitchforks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. We can investigate the BOM issue afterward.

@tannergooding tannergooding enabled auto-merge (squash) February 19, 2026 01:44
@jeffhandley
Copy link
Member

/ba-g Unrelated networking failures on Android only

@tannergooding tannergooding merged commit 1451f24 into dotnet:main Feb 19, 2026
147 of 149 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-System.Buffers community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Base64Url.DecodeFromChars crashes with AccessViolationException on non-ASCII char input (Microsoft.Bcl.Memory)

5 participants

Comments