GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — gh-137273: Fix debug assertion failure in locale.setlocale() on Windows by serhiy-storchaka · Pull Request #137300 · python/cpython Conversation
|
| size_t len = end ? (size_t)(end - locale) : strlen(locale); | ||
| const char *dot = memchr(locale, '.', len); | ||
| if (dot && locale + len - dot > 16) { | ||
| return -1; |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Where did you get the "16" from ?
Please include some comments to explain where you got it from and why this check is necessary. Thanks.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
BTW: It's better to make this limit configurable via a constant.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Comes from https://github.com/huangqinjin/ucrt/blob/d6e817a4cc90f6f1fe54f8a0aa4af4fff0bb647d/inc/corecrt_internal.h#L401, though I don't think that constant is available for us at compile time (the internal headers for the CRT are, well, internal).
A constant at least gives it a name though, and using MAX_CP_LEN may help someone find an updated definition in the future.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Looks good now.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
When you're done making the requested changes, leave the comment: |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
How to check the Windows version? I do not have Windows 11, can you please test this PR on Windows 11? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
I wouldn't bother, this limit has been around forever. The bigger challenge would be how to handle |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Sorry, but I don't have a Windows 11 build system available at the moment (not even a working Win10 system, after the VM crashed some time ago). Let's not worry about this now. We can disable things again selectively, once the Windows SDK provides better support for handling locale names (perhaps in a few years). |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
I am planning to handle this in Python code. Translate "zh_HK.UTF-8@hans" to "zh-Hans-HK.utf-8", etc. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Is that how Windows handles modifiers ? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I have made the requested changes; please review again. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Thanks for making the requested changes! @malemburg: please review the changes made to this pull request. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| size_t len = end ? (size_t)(end - locale) : strlen(locale); | ||
| const char *dot = memchr(locale, '.', len); | ||
| if (dot && locale + len - dot > 16) { | ||
| return -1; |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Looks good now.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
No - Windows UCRT treats them as part of the code page name and overruns its own buffers, leading to a crash 😉 I don't think there's any support for modifiers in locales at all. The OS itself has always used a different system for those AFAICT, it's just the POSIX emulation in the CRT that's trying to fudge over it. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
In that case, it's probably best to simply strip from them locale strings passed to |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Yes. It supports format I seen also |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Thanks @serhiy-storchaka for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
… Windows (pythonGH-137300) It happened when there were at least 16 characters after dot in the locale name. (cherry picked from commit 718e0c8) Co-authored-by: Serhiy Storchaka <[email protected]>
… Windows (pythonGH-137300) It happened when there were at least 16 characters after dot in the locale name. (cherry picked from commit 718e0c8) Co-authored-by: Serhiy Storchaka <[email protected]>
|
GH-137305 is a backport of this pull request to the 3.14 branch. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
GH-137306 is a backport of this pull request to the 3.13 branch. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…n Windows (GH-137300) (GH-137306) It happened when there were at least 16 characters after dot in the locale name. (cherry picked from commit 718e0c8) Co-authored-by: Serhiy Storchaka <[email protected]>
|
Thank you for your review, @malemburg and @zooba. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
… Windows (pythonGH-137300) It happened when there were at least 16 characters after dot in the locale name.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.