Uh oh!
There was an error while loading. Please reload this page.
Base64.Decode: fixed latent bug for non-ASCII inputs - #76795
Conversation
ghost
commented
Oct 9, 2022
Tagging subscribers to this area: @dotnet/area-system-memory Issue DetailsRepro: stringbase64="ìz/TpH7sqEkerqMweH1uSw==";// first char is not ASCIIbyte[]base64Bytes=Encoding.UTF8.GetBytes(base64);Span<byte>data=stackallocbyte[128];OperationStatusstatus=Base64_.DecodeFromUtf8(base64Bytes,data,outintconsumed,outintwritten);Here the
fails as the length doesn't match (base64-len is 24, base64Bytes-len is 25). 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.
doesn't detect the non-ASCII / non-base64 char. By masking with
|
Uh oh!
There was an error while loading. Please reload this page.
gfoidl
commented
Oct 9, 2022
In CI there's lots of When the org is online again, someone please re-trigger the build. Thanks in advance. |
kasperk81
commented
Oct 9, 2022
no clue. maintenance breaks should be publicly announced either at https://github.com/dotnet/announcements/issues or https://github.com/dotnet/core/issues |
adamsitnik
left a comment
There was a problem hiding this comment.
LGMT, thank you for the fix @gfoidl !
Uh oh!
There was an error while loading. Please reload this page.
adamsitnik
commented
Oct 10, 2022
/backport to release/7.0 |
Started backporting to release/7.0: https://github.com/dotnet/runtime/actions/runs/3219528468 |
MattGal
commented
Oct 10, 2022
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. |
stephentoub
commented
Oct 10, 2022
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
InvalidDatacorrectly, 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
0xFwe clear the highest bit -- actually we mask by0x2Fas that constant is used somewhere else and for shuffling (besides the highest bit) only the lower-nibble of the mask-byte is relevant.