-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Base64.Decode: fixed latent bug for non-ASCII inputs #76795
Conversation
Tagging subscribers to this area: @dotnet/area-system-memory Issue DetailsRepro: string base64 = "ìz/TpH7sqEkerqMweH1uSw=="; // first char is not ASCII
byte[] base64Bytes = Encoding.UTF8.GetBytes(base64);
Span<byte> data = stackalloc byte[128];
OperationStatus status = Base64_.DecodeFromUtf8(base64Bytes, data, out int consumed, out int written); Here the runtime/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Decoder.cs Line 200 in f33d778
So status reports InvalidData correctly, but consumed (24) and written (17) are wrong, as they should be 0 each.
This latent bug got introduced by #70654, and unfortunately there was a test-hole that didn't catch this. runtime/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Decoder.cs Lines 598 to 601 in f33d778
By masking with
|
src/libraries/System.Memory/tests/Base64/Base64DecoderUnitTests.cs
Outdated
Show resolved
Hide resolved
In CI there's lots of
When the org is online again, someone please re-trigger the build. Thanks in advance. |
no clue. maintenance breaks should be publicly announced either at https://github.com/dotnet/announcements/issues or https://github.com/dotnet/core/issues |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGMT, thank you for the fix @gfoidl !
src/libraries/System.Memory/tests/Base64/Base64DecoderUnitTests.cs
Outdated
Show resolved
Hide resolved
/backport to release/7.0 |
Started backporting to release/7.0: https://github.com/dotnet/runtime/actions/runs/3219528468 |
Things are back to normal now, but yes I agree this was less than ideal. The expectation from previous migrations was that this should have taken a few hours, but once it started it had to be completed. It was expected that an Azure Devops Banner and partners DL email was enough, but clearly it caught people by surprise and we'll take these learnings for the next time a scheduled downtime happens. |
There was no indication anywhere in dotnet/runtime, at least not that I saw. |
Repro:
Here the
ì
isn't recognized as being not part of the base64-alphabet, so wrong data is decoded. Ultimately the checkruntime/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Decoder.cs
Line 200 in f33d778
So status reports
InvalidData
correctly, but consumed (24) and written (17) are wrong, as they should be 0 each.This latent bug got introduced by #70654, and unfortunately there was a test-hole that didn't catch this.
#70654 (comment) talks about the shuffle mask -- here the highest bit of the mask-byte is set so after the shuffle the bits of that vector-element are set to
0
, thusruntime/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Decoder.cs
Lines 598 to 601 in f33d778
By masking with
0xF
we clear the highest bit -- actually we mask by0x2F
as that constant is used somewhere else and for shuffling (besides the highest bit) only the lower-nibble of the mask-byte is relevant.