Handle '/' in locale name in PAL (#46601)
authorAdeel Mujahid <3840695+am11@users.noreply.github.com>
Wed, 6 Jan 2021 00:29:56 +0000 (02:29 +0200)
committerGitHub <noreply@github.com>
Wed, 6 Jan 2021 00:29:56 +0000 (16:29 -0800)
src/libraries/Native/Unix/System.Globalization.Native/pal_locale.c
src/libraries/System.Globalization/tests/CultureInfo/GetCultureInfo.cs

index a96d5d9..5024fb0 100644 (file)
@@ -46,7 +46,11 @@ int32_t GetLocale(const UChar* localeName,
     {
         UChar c = localeName[i];
 
-        if (c > (UChar)0x7F)
+        // Some versions of ICU have a bug where '/' in name can cause infinite loop, so we preemptively
+        // detect this case for CultureNotFoundException (as '/' is anyway illegal in locale name and we
+        // expected ICU to return this error).
+
+        if (c > (UChar)0x7F || c == (UChar)'/')
         {
             *err = U_ILLEGAL_ARGUMENT_ERROR;
             return ULOC_FULLNAME_CAPACITY;
index c5a3d5c..8ddfe93 100644 (file)
@@ -25,6 +25,7 @@ namespace System.Globalization.Tests
         [ConditionalTheory(nameof(PlatformSupportsFakeCulture))]
         [InlineData("en@US")]
         [InlineData("\uFFFF")]
+        [InlineData("/")]
         public void TestInvalidCultureNames(string name)
         {
             Assert.Throws<CultureNotFoundException>(() => CultureInfo.GetCultureInfo(name));