.NET 11 fails to decode certain base64 inputs
- Dominant language
- C#
- Stars
- 18.3k
- Forks
- 5.6k
- PR merge metrics
- PR metrics pending
Description
### Description
I've observed a serious regression in one of my unit tests after updating the project to target .NET 11. I've isolated minimal reproducible one-liner in the meantime to aid debugging.
### Reproduction Steps
`dotnet new console`, then in `Program.cs`:
```
Console.WriteLine($"OK: {Convert.FromBase64String("KDHC3rsY8+CmiswnXJcE5e5dRfd=").Length}");
```
### Expected behavior
Should work fine with `OK: 20` output, which is the case when running this against `net10.0`
### Actual behavior
```
Unhandled exception. System.FormatException: The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or an illegal character among the padding characters.
at System.Buffers.Text.Base64.DecodeFromChars(ReadOnlySpan`1 source)
at Program.$(String[] args) in Program.cs:line 1
```
Happens with `net11.0`
As a side note, not every valid base64 input results in this regression, but I've found at least one that does, which you can hardcode for unit test later on if deemed wanted.
### Regression?
Yes, worked fine in .NET 10
### Known Workarounds
None for now.
### Configuration
```
.NET SDK:
Version: 11.0.100-rc.1.26425.128
Commit: 3551975be0
Workload version: 11.0.100-rc.1.26458.5
MSBuild version: 18.11.0-1.26425.128+3551975be
Runtime Environment:
OS Name: debian
OS Version:
OS Platform: Linux
RID: linux-x64
Base Path: /usr/share/dotnet/sdk/11.0.100-rc.1.26425.128
.NET workloads installed:
Brak zainstalowanych obciążeń do wyświetlenia.
Skonfigurowano używanie workload sets podczas instalowania nowych manifestów.
Host:
Version: 11.0.0-rc.1.26425.128
Architecture: x64
Commit: 3551975be0
.NET SDKs installed:
11.0.100-rc.1.26425.128 [/usr/share/dotnet/sdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 10.0.12 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 11.0.0-rc.1.26425.128 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 10.0.12 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 11.0.0-rc.1.26425.128 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
Other architectures found:
None
Environment variables:
DOTNET_CLI_TELEMETRY_OPTOUT [true]
DOTNET_NOLOGO [true]
global.json file:
Not found
Learn more:
https://aka.ms/dotnet/info
Download .NET:
https://aka.ms/dotnet/download
```
### Other information
I don't see any user error, neither a mention in the changelog regarding that - especially considering this is a valid base64 input that worked before.
I'd recommend to take a look into it before full release, as it seems rather serious to me and is a blocker right now for several of my projects.
Contributor guide
Research direction
Start by reproducing the failure with the provided Program.cs one-liner under net11.0 and compare it with net10.0, then follow the stack trace into Convert.FromBase64String and System.Buffers.Text.Base64.DecodeFromChars. Done means the valid input decodes successfully to 20 bytes and a regression test covers the case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 42/100