-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix Native Digit Reading #58598
Fix Native Digit Reading #58598
Conversation
Tagging subscribers to this area: @tarekgh, @safern Issue DetailsWhen creating any culture, we read the culture data from the underlying OS library (either NLS or ICU). Part of the data we read is the culture native digits. We should get ten digits string (e.g. It is hard to add a test for such fix as it will need to change the machine settings. But, I have tested manually and ensured it address the issue when having wrong settings.
|
src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.cs
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice. LGTM
@@ -2138,29 +2138,33 @@ private string[] GetNativeDigits() | |||
|
|||
// if digits.Length < NumberFormatInfo.s_asciiDigits.Length means the native digits setting is messed up in the host machine. | |||
// Instead of throwing IndexOutOfRangeException that will be hard to diagnose after the fact, we'll fall back to use the ASCII digits instead. | |||
if (digits.Length >= NumberFormatInfo.s_asciiDigits.Length) | |||
if (digits.Length < NumberFormatInfo.s_asciiDigits.Length) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I'm missing something obvious -- why is this <
rather than !=
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
digits
can include null termination character at the end.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
When creating any culture, we read the culture data from the underlying OS library (either NLS or ICU). Part of the data we read is the culture native digits. We should get ten digits string (e.g.
0123456789
). Sometime the settings in the host machine get messed up and can return digits strings less than ten digits and that can cause .NET to throwIndexOutOfRangeException
. Such failure is hard to diagnose after the fact especially when the collected dumps don't include the machine settings. This issue gets reported every while and recently we get it again from some customer. The change here is only read the returned digits data if it is ten digits. Otherwise, we'll fallback to ASCII digitsIt is hard to add a test for such fix as it will need to change the machine settings. But, I have tested manually and ensured it address the issue when having wrong settings.