-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Closed
Labels
Description
Description
When calling FromBase64Transform .TransformBlock with a destination buffer that is too small, debug builds of the runtime will assert here:
Line 312 in ec72407
| Debug.Assert(status == OperationStatus.InvalidData); |
Release builds of the runtime will do ThrowBase64FormatException, implying the base-64 is malformed, not that the destination buffer is too small. The call to Base64.DecodeFromUtf8 is returning DestinationTooSmall, which hits the assert.
I would expect it handle the destination as too small by doing
ThrowHelper.ThrowArgumentOutOfRange(ThrowHelper.ExceptionArgument.outputBuffer);Reproduction Steps
A simple test that reproduces the issue:
[Fact]
public static void FromBase64Transform_OutputBufferTooSmall()
{
using FromBase64Transform transform = new();
byte[] destination = new byte[0];
byte[] block = "AAAA"u8.ToArray();
AssertExtensions.Throws<ArgumentOutOfRangeException>("outputBuffer",
() => transform.TransformBlock(block, 0, block.Length, destination, 0));
}Expected behavior
Throw ArgumentOutOfRangeException.
Actual behavior
Assert in debug builds:
Expected: typeof(System.ArgumentOutOfRangeException)
Actual: typeof(Microsoft.VisualStudio.TestPlatform.TestHost.DebugAssertException)
---- Microsoft.VisualStudio.TestPlatform.TestHost.DebugAssertException : Method Debug.Fail failed with 'status == OperationStatus.InvalidData
', and was translated to Microsoft.VisualStudio.TestPlatform.TestHost.DebugAssertException to avoid terminating the process hosting the test.
Stack Trace:
at System.AssertExtensions.Throws[T](String expectedParamName, Func`1 testCode) in /Users/vcsjones/Projects/runtime/src/libraries/Common/tests/TestUtilities/System/AssertExtensions.cs:line 146
at System.Security.Cryptography.Tests.Base64TransformsTests.FromBase64Transform_OutputBufferTooSmall() in /Users/vcsjones/Projects/runtime/src/libraries/System.Security.Cryptography/tests/Base64TransformsTests.cs:line 286
at System.RuntimeMethodHandle.InvokeMethod(ObjectHandleOnStack target, Void** arguments, ObjectHandleOnStack sig, BOOL isConstructor, ObjectHandleOnStack result)
at System.RuntimeMethodHandle.InvokeMethod(ObjectHandleOnStack target, Void** arguments, ObjectHandleOnStack sig, BOOL isConstructor, ObjectHandleOnStack result)
at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor) in /Users/vcsjones/Projects/runtime/src/coreclr/System.Private.CoreLib/src/System/RuntimeHandles.cs:line 1165
at System.Reflection.MethodBaseInvoker.InterpretedInvoke_Method(Object obj, IntPtr* args) in /Users/vcsjones/Projects/runtime/src/coreclr/System.Private.CoreLib/src/System/Reflection/MethodBaseInvoker.CoreCLR.cs:line 36
at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr) in /Users/vcsjones/Projects/runtime/src/libraries/System.Private.CoreLib/src/System/Reflection/MethodBaseInvoker.cs:line 57
Regression?
No response
Known Workarounds
No response
Configuration
No response
Other information
No response