Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.3k
gh-130567: Remove optimistic allocation in locale.strxfrm()#137143
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
On modern systems, the result of wcsxfrm() is much larger the size ofthe input string (from 4+2*n on Windows to 4+5*n on Linux for simpleASCII strings), so optimistic allocation of the buffer of the same sizenever works.
Modules/_localemodule.c Outdated
| gotoexit; | ||
| } | ||
| /* assume no change in size, first */ |
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.
The comment should be updated to match changed code.
If this is a bug fix, it needs a NEWS entry. If the bug will be fixed in other way -- it is just cleanup and minor optimization not worth a NEWS entry. |
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.
This does not fix the bug; macOS raisesEINVAL inwcsxfrm(NULL, s, 0) on the Czech and Chinese strings.
So, it's just cleanup and minor optimization.
Actually, optimistic allocation works if the locale was not set or set to "C". But why would you use |
This PR should fix a crash discussed in#130567 (comment). So this is a bug fix. If we are not going to backport it, we need another PR to fix it. |
encukou commentedSep 10, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Let's backport it [edit: to 3.14.1], even if can't reproduce the corruption on my system. |
Created a simpler PR#138940 for the fix. |
Do you want to update this one? |
2a2bc82 intopython:mainUh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
On modern systems, the result of wcsxfrm() is much larger the size of the input string (from 4+2n on Windows to 4+5n on Linux for simple ASCII strings), so optimistic allocation of the buffer of the same size never works.