Skip to content
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

Merged
merged 3 commits into from
Sep 4, 2021
Merged

Conversation

tarekgh
Copy link
Member

@tarekgh tarekgh commented Sep 3, 2021

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 throw IndexOutOfRangeException. 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 digits

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.

@ghost
Copy link

ghost commented Sep 3, 2021

Tagging subscribers to this area: @tarekgh, @safern
See info in area-owners.md if you want to be subscribed.

Issue Details

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 throw IndexOutOfRangeException. 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 digits

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.

Author: tarekgh
Assignees: -
Labels:

area-System.Globalization

Milestone: -

Copy link
Member

@eerhardt eerhardt left a 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)
Copy link
Member

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 !=

Copy link
Member Author

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.

@tarekgh tarekgh merged commit 4bdd679 into dotnet:main Sep 4, 2021
@tarekgh tarekgh deleted the FixNativeDigitsReading branch September 4, 2021 00:01
Copy link
Member

@safern safern left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@ghost ghost locked as resolved and limited conversation to collaborators Nov 3, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants