Skip to content

Remove some of unsafe code in Base64 decoder#124761

Closed
EgorBo wants to merge 1 commit intodotnet:mainfrom
EgorBo:remove-unsafe-base64-decoder
Closed

Remove some of unsafe code in Base64 decoder#124761
EgorBo wants to merge 1 commit intodotnet:mainfrom
EgorBo:remove-unsafe-base64-decoder

Conversation

@EgorBo
Copy link
Copy Markdown
Member

@EgorBo EgorBo commented Feb 23, 2026

Still keeping some unsafe for hot SIMD loop (will try to remove that too) or if it has a lot of unsafe callers

@dotnet-policy-service
Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR reduces unsafe code usage in the Base64 / Base64Url decoding helpers by switching the scalar decoding helpers from raw pointers to ReadOnlySpan<T> and index-based processing, while keeping unsafe code for the SIMD hot loops.

Changes:

  • Updated IBase64Decoder<T> to decode scalar blocks via ReadOnlySpan<T> instead of T* pointers.
  • Adjusted Base64Url decoder wrappers to match the new span-based decoder API.
  • Refactored core decode helpers to use indices + spans (and updated the “write 3 bytes” helper accordingly), limiting pinning to SIMD paths.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Url/Base64UrlDecoder.cs Updates Base64Url decoder wrapper methods to use span-based scalar decode APIs (removes unsafe pointer params for these helpers).
src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Helper/Base64Helper.cs Changes IBase64Decoder<T> scalar decode method signatures from pointers to ReadOnlySpan<T>.
src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Helper/Base64DecoderHelper.cs Refactors scalar decoding and in-place decoding loops to use spans/indices instead of pointer arithmetic; keeps pinning only for SIMD decode paths.

@EgorBo
Copy link
Copy Markdown
Member Author

EgorBo commented Feb 23, 2026

@MihuBot

@EgorBo EgorBo force-pushed the remove-unsafe-base64-decoder branch from 1caff26 to b30129c Compare February 23, 2026 21:07
@EgorBo
Copy link
Copy Markdown
Member Author

EgorBo commented Feb 23, 2026

@MihuBot

@EgorBo
Copy link
Copy Markdown
Member Author

EgorBo commented Feb 23, 2026

@EgorBot -arm -amd --filter "Perf_Base64"

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants