@@ -369,7 +369,7 @@ internal static CultureData GetCultureDataForRegion(String cultureName, bool use
369
369
}
370
370
371
371
// If not found in the hard coded table we'll have to find a culture that works for us
372
- if ( retVal == null || ( retVal . IsNeutralCulture == true ) )
372
+ if ( ! GlobalizationMode . Invariant && ( retVal == null || ( retVal . IsNeutralCulture == true ) ) )
373
373
{
374
374
retVal = GetCultureDataFromRegionName ( cultureName ) ;
375
375
}
@@ -415,7 +415,7 @@ internal static CultureInfo[] GetCultures(CultureTypes types)
415
415
CultureTypes . ReplacementCultures | CultureTypes . WindowsOnlyCultures |
416
416
CultureTypes . FrameworkCultures ) ) != 0 )
417
417
{
418
- throw new ArgumentOutOfRangeException ( nameof ( types ) ,
418
+ throw new ArgumentOutOfRangeException ( nameof ( types ) ,
419
419
SR . Format ( SR . ArgumentOutOfRange_Range , CultureTypes . NeutralCultures , CultureTypes . FrameworkCultures ) ) ;
420
420
}
421
421
@@ -429,7 +429,7 @@ internal static CultureInfo[] GetCultures(CultureTypes types)
429
429
// Remove the enum as it is an no-op.
430
430
types &= ( ~ CultureTypes . WindowsOnlyCultures ) ;
431
431
}
432
-
432
+
433
433
if ( GlobalizationMode . Invariant )
434
434
{
435
435
// in invariant mode we always return invariant culture only from the enumeration
@@ -539,7 +539,7 @@ private static CultureData CreateCultureWithInvariantData()
539
539
invariant . _iDefaultOemCodePage = 437 ; // default oem code page ID (OCP or OEM)
540
540
invariant . _iDefaultMacCodePage = 10000 ; // default macintosh code page
541
541
invariant . _iDefaultEbcdicCodePage = 037 ; // default EBCDIC code page
542
-
542
+
543
543
if ( GlobalizationMode . Invariant )
544
544
{
545
545
invariant . _sLocalizedDisplayName = invariant . _sNativeDisplayName ;
@@ -631,7 +631,11 @@ private static unsafe string NormalizeCultureName(string name, out bool isNeutra
631
631
isNeutralName = true ;
632
632
int i = 0 ;
633
633
634
- Debug . Assert ( name . Length <= LOCALE_NAME_MAX_LENGTH ) ;
634
+ if ( name . Length > LOCALE_NAME_MAX_LENGTH )
635
+ {
636
+ // Theoretically we shouldn't hit this exception.
637
+ throw new ArgumentException ( SR . Format ( SR . Argument_InvalidId , nameof ( name ) ) ) ;
638
+ }
635
639
636
640
char * pName = stackalloc char [ LOCALE_NAME_MAX_LENGTH ] ;
637
641
bool changed = false ;
@@ -673,15 +677,18 @@ private static unsafe string NormalizeCultureName(string name, out bool isNeutra
673
677
674
678
if ( changed )
675
679
return new string ( pName , 0 , name . Length ) ;
676
-
680
+
677
681
return name ;
678
682
}
679
683
680
684
private static CultureData CreateCultureData ( string cultureName , bool useUserOverride )
681
685
{
682
686
if ( GlobalizationMode . Invariant )
683
687
{
684
- CultureInfo . VerifyCultureName ( cultureName , true ) ;
688
+ if ( cultureName . Length > LOCALE_NAME_MAX_LENGTH || ! CultureInfo . VerifyCultureName ( cultureName , false ) )
689
+ {
690
+ return null ;
691
+ }
685
692
CultureData cd = CreateCultureWithInvariantData ( ) ;
686
693
cd . _bUseOverrides = useUserOverride ;
687
694
cd . _sName = NormalizeCultureName ( cultureName , out cd . _bNeutral ) ;
@@ -749,7 +756,7 @@ internal static CultureData GetCultureData(int culture, bool bUseUserOverride)
749
756
750
757
if ( culture == CultureInfo . LOCALE_INVARIANT )
751
758
return Invariant ;
752
-
759
+
753
760
if ( GlobalizationMode . Invariant )
754
761
{
755
762
// LCID is not supported in the InvariantMode
@@ -894,7 +901,7 @@ internal String SLOCALIZEDDISPLAYNAME
894
901
}
895
902
else
896
903
{
897
- // Usually the UI culture shouldn't be different than what we got from WinRT except
904
+ // Usually the UI culture shouldn't be different than what we got from WinRT except
898
905
// if DefaultThreadCurrentUICulture was set
899
906
CultureInfo ci ;
900
907
@@ -1065,7 +1072,7 @@ internal String SLOCALIZEDLANGUAGE
1065
1072
{
1066
1073
if ( _sLocalizedLanguage == null )
1067
1074
{
1068
- // Usually the UI culture shouldn't be different than what we got from WinRT except
1075
+ // Usually the UI culture shouldn't be different than what we got from WinRT except
1069
1076
// if DefaultThreadCurrentUICulture was set
1070
1077
CultureInfo ci ;
1071
1078
@@ -1153,7 +1160,7 @@ internal string SLOCALIZEDCOUNTRY
1153
1160
}
1154
1161
catch ( Exception )
1155
1162
{
1156
- // do nothing. we'll fallback
1163
+ // do nothing. we'll fallback
1157
1164
}
1158
1165
1159
1166
if ( _sLocalizedCountry == null )
@@ -2390,8 +2397,8 @@ internal void GetNFIValues(NumberFormatInfo nfi)
2390
2397
// This is ONLY used for caching names and shouldn't be used for anything else
2391
2398
internal static string AnsiToLower ( string testString )
2392
2399
{
2393
- int index = 0 ;
2394
-
2400
+ int index = 0 ;
2401
+
2395
2402
while ( index < testString . Length && ( testString [ index ] < 'A' || testString [ index ] > 'Z' ) )
2396
2403
{
2397
2404
index ++ ;
@@ -2400,7 +2407,7 @@ internal static string AnsiToLower(string testString)
2400
2407
{
2401
2408
return testString ; // we didn't really change the string
2402
2409
}
2403
-
2410
+
2404
2411
StringBuilder sb = new StringBuilder ( testString . Length ) ;
2405
2412
for ( int i = 0 ; i < index ; i ++ )
2406
2413
{
0 commit comments