diff --git a/src/libraries/System.Memory/tests/Base64Url/Base64UrlUnicodeAPIsUnitTests.cs b/src/libraries/System.Memory/tests/Base64Url/Base64UrlUnicodeAPIsUnitTests.cs index a455075bb9c7ed..43e950e4686f16 100644 --- a/src/libraries/System.Memory/tests/Base64Url/Base64UrlUnicodeAPIsUnitTests.cs +++ b/src/libraries/System.Memory/tests/Base64Url/Base64UrlUnicodeAPIsUnitTests.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using System.Collections.Generic; @@ -196,7 +196,8 @@ public static IEnumerable EncodeToStringTests_TestData() } [Theory] - [InlineData("\u5948cz_T", 0, 0)] // scalar code-path + [InlineData("AB\u1000D", 0, 0)] // scalar code-path, non-ASCII char > 255 (https://github.com/dotnet/runtime/issues/124513) + [InlineData("\u5948cz_T", 0, 0)] // scalar code-path [InlineData("z_Ta123\u5948", 4, 3)] [InlineData("\u5948z_T-H7sqEkerqMweH1uSw==", 0, 0)] // Vector128 code-path [InlineData("z_T-H7sqEkerqMweH1uSw\u5948==", 20, 15)] diff --git a/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Helper/Base64DecoderHelper.cs b/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Helper/Base64DecoderHelper.cs index c94f8dfe9963a7..7c6d47a3493ee7 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Helper/Base64DecoderHelper.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Buffers/Text/Base64Helper/Base64DecoderHelper.cs @@ -168,6 +168,11 @@ internal static unsafe OperationStatus DecodeFrom(TBase64Deco Debug.Assert(typeof(TBase64Decoder) == typeof(Base64DecoderByte) ? remaining == 4 : remaining < 8); int i0 = decoder.DecodeRemaining(srcEnd, ref decodingMap, remaining, out uint t2, out uint t3); + if (i0 < 0) + { + goto InvalidDataExit; + } + byte* destMax = destBytes + (uint)destLength; if (!decoder.IsValidPadding(t3))