Add Base64url encoding/decoding#102364
Conversation
|
Note regarding the |
gfoidl
left a comment
There was a problem hiding this comment.
Just skimmed over it...
I saw your comment, but for checking perf some of my comments may help (a bit).
src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Decoder.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Url/Base64UrlDecoder.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Url/Base64UrlDecoder.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Url/Base64UrlEncoder.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Url/Base64UrlEncoder.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Url/Base64UrlEncoder.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Url/Base64UrlValidator.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Validator.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: Günther Foidl <gue@korporal.at>
|
/benchmark |
Thank you, sure perf related feedbacks appreciated, I updated the description, any feedbacks are welcome. |
|
Crank Pull Request Bot
Benchmarks:
Profiles:
Components:
Arguments: any additional arguments to pass through to crank, e.g. |
This comment was marked as duplicate.
This comment was marked as duplicate.
This comment was marked as duplicate.
This comment was marked as duplicate.
This comment was marked as duplicate.
This comment was marked as duplicate.
src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems
Show resolved
Hide resolved
Co-authored-by: Jeremy Barton <jbarton@microsoft.com>
| padding++; | ||
| } | ||
|
|
||
| if (TBase64Decoder.IsValidPadding(Unsafe.Subtract(ref ptrToLastElement, 1))) |
There was a problem hiding this comment.
What guarantees this is in bounds?
There was a problem hiding this comment.
This is only called with a buffer that has size of 4
src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Decoder.cs
Outdated
Show resolved
Hide resolved
| } | ||
|
|
||
| end = srcMax - 64; | ||
| end = srcMax - 32; |
There was a problem hiding this comment.
Why did this change from 64 to 32?
There was a problem hiding this comment.
It was 32 originally, but unintentionally changed with this PR
The method comment also mentions it require 32 byte
src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Url/Base64UrlValidator.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Decoder.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Decoder.cs
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Decoder.cs
Show resolved
Hide resolved
| where TBase64Decoder : IBase64Decoder<byte> | ||
| { | ||
| const int BlockSize = 4; | ||
| int BlockSize = Math.Min(source.Length - (int)sourceIndex, 4); |
There was a problem hiding this comment.
Would anything bad happen if this were left at a const 4?
This not being const would penalize the non-url path as well a bit.
There was a problem hiding this comment.
For Base64Url when the source is not multiple of 4 we need to adjust the buffer size accordingly, the BlockSize value used to fill the whitespace with padding (row 653) so that it could decoded correctly (in case remaining bytes were decodable or valid)
|
@MihuBot fuzz Base64 |
|
also showing regressions in dotnet/perf-autofiling-issues#36512 and improvements dotnet/perf-autofiling-issues#36643 |
Base64Url encoding doesn't append padding, therefore encoded byte count differs from Base64 encoding:
Base64Url decoding ignore whitespace and padding, therefore decodable byte count differs from Base64 decoding, the exact decoding result also depend on
isFinalBlockand if padding involvedApproved API shape:
Draft PR until below list is completed, for now mainly for checking perf, run tests on different CI legs, and get early feedback.
Fixes #1658