Fix FromBase64Transform.TransformFinalBlock to consistently reset state#124480
Open
Fix FromBase64Transform.TransformFinalBlock to consistently reset state#124480
Conversation
Co-authored-by: vcsjones <361677+vcsjones@users.noreply.github.com>
Co-authored-by: vcsjones <361677+vcsjones@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix FromBase64Transform.TransformFinalBlock inconsistent state clearing
Fix FromBase64Transform.TransformFinalBlock to consistently reset state
Feb 16, 2026
vcsjones
approved these changes
Feb 16, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes FromBase64Transform.TransformFinalBlock to always reset internal buffered state when finalizing, including the inputCount == 0 early-return path, preventing subsequent decode operations from being corrupted by stale _inputIndex state.
Changes:
- Call
Reset()whenTransformFinalBlockis invoked with empty input (inputCount == 0). - Add a regression test ensuring consistent reset behavior for empty (0 bytes) and partial (1 byte) final blocks.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/Base64Transforms.cs | Resets FromBase64Transform state on the inputCount == 0 early return to avoid stale buffered state. |
| src/libraries/System.Security.Cryptography/tests/Base64TransformsTests.cs | Adds a theory-based regression test validating state reset for both empty and 1-byte final blocks. |
src/libraries/System.Security.Cryptography/tests/Base64TransformsTests.cs
Show resolved
Hide resolved
Contributor
|
Tagging subscribers to this area: @bartonjs, @vcsjones, @dotnet/area-system-security |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
FromBase64Transform.TransformFinalBlockfailed to reset internal state when called with empty input (inputCount == 0), while correctly resetting for partial blocks (bytesToTransform < InputBlockSize). This left_inputIndexwith stale data, causing subsequent transform operations to fail.Changes:
Reset()call before early return at line 192 wheninputCount == 0TransformFinalBlock_ShouldResetStateConsistentlycovering both empty (0 bytes) and partial (1 byte) final block scenariosExample of the issue:
All 62 Base64Transform tests pass.
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
http://www.microsoft.com:80/pkiops/certs/Microsoft%20Azure%20RSA%20TLS%20Issuing%20CA%2008%20-%20xsign.crt/home/REDACTED/work/runtime/runtime/artifacts/bin/testhost/net11.0-linux-Debug-x64/dotnet /home/REDACTED/work/runtime/runtime/artifacts/bin/testhost/net11.0-linux-Debug-x64/dotnet exec --runtimeconfig System.Security.Cryptography.Tests.runtimeconfig.json --depsfile System.Security.Cryptography.Tests.deps.json /home/REDACTED/.nuget/packages/microsoft.dotnet.xunitconsoleREDACTED/2.9.3-beta.26110.116/build/../tools/net/xunit.console.dll System.Security.Cryptography.Tests.dll -xml testResults.xml -nologo -notrait category=OuterLoop -notrait category=failing -method System.Security.Cryptography.Tests.Base64TransformsTests.TransformFinalBlock_ShouldResetStateConsistently x86_64-pc-linux---version -18 GET_AMD64 -DTARGfxr/staticlib/CMakeFiles/libhostfxr.dir/__/__/fx_definition.cpp.o(http block)/home/REDACTED/work/runtime/runtime/artifacts/bin/testhost/net11.0-linux-Debug-x64/dotnet /home/REDACTED/work/runtime/runtime/artifacts/bin/testhost/net11.0-linux-Debug-x64/dotnet exec --runtimeconfig System.Security.Cryptography.Tests.runtimeconfig.json --depsfile System.Security.Cryptography.Tests.deps.json /home/REDACTED/.nuget/packages/microsoft.dotnet.xunitconsoleREDACTED/2.9.3-beta.26110.116/build/../tools/net/xunit.console.dll System.Security.Cryptography.Tests.dll -xml testResults.xml -nologo -notrait category=OuterLoop -notrait category=failing -method System.Security.Cryptography.Tests.Base64TransformsTests.TransformFinalBlock_ShouldResetStateConsistently Y_INTERNAL inja e/.dotnet/dotnet/nologo(http block)/home/REDACTED/work/runtime/runtime/artifacts/bin/testhost/net11.0-linux-Debug-x64/dotnet /home/REDACTED/work/runtime/runtime/artifacts/bin/testhost/net11.0-linux-Debug-x64/dotnet exec --runtimeconfig System.Security.Cryptography.Tests.runtimeconfig.json --depsfile System.Security.Cryptography.Tests.deps.json /home/REDACTED/.nuget/packages/microsoft.dotnet.xunitconsoleREDACTED/2.9.3-beta.26110.116/build/../tools/net/xunit.console.dll System.Security.Cryptography.Tests.dll -xml testResults.xml -nologo -notrait category=OuterLoop -notrait category=failing -method System.Security.Cryptography.Tests.Base64TransformsTests.TransformFinalBlock_ShouldResetStateConsistently tive inja /bin/sh(http block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.