Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Merged
encukou merged 3 commits intopython:mainfromserhiy-storchaka:locale-wcsxfrm
Oct 16, 2025

Conversation

@serhiy-storchaka
Copy link
Member

@serhiy-storchakaserhiy-storchaka commentedJul 27, 2025
edited by bedevere-appbot
Loading

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.

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.
gotoexit;
}

/* assume no change in size, first */
Copy link
Contributor

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.

serhiy-storchaka reacted with thumbs up emoji
@picnixzpicnixz changed the titleRemove optimistic allocation in locale.strxfrm()gh-130567: Remove optimistic allocation in locale.strxfrm()Jul 27, 2025
@serhiy-storchaka
Copy link
MemberAuthor

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.

Copy link
Member

@encukouencukou left a 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.

@serhiy-storchaka
Copy link
MemberAuthor

Actually, optimistic allocation works if the locale was not set or set to "C".

>>> import locale>>> locale.strxfrm('abc')'abc'>>> locale.setlocale(locale.LC_ALL, 'C')'C'>>> locale.strxfrm('abc')'abc'>>> locale.setlocale(locale.LC_ALL, 'en_US.UTF-8')'en_US.UTF-8'>>> locale.strxfrm('abc')'šŮŹ\x01\x1d\x1d\x1d\x01\x02\x02\x02\x01\x01悝\x01惹\x01愝'

But why would you uselocale.strxfrm() in the C locale? And since the call ofwcsxfrm() is cheap in the C locale, I believe that the loss in the worst case is less that the gain in average.

encukou reacted with thumbs up emoji

@serhiy-storchaka
Copy link
MemberAuthor

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
Copy link
Member

encukou commentedSep 10, 2025
edited
Loading

Let's backport it [edit: to 3.14.1], even if can't reproduce the corruption on my system.
“Fix possible crash instrxfrm” should be a good blurb?

@serhiy-storchaka
Copy link
MemberAuthor

Created a simpler PR#138940 for the fix.

@encukou
Copy link
Member

Do you want to update this one?

@encukouencukou merged commit2a2bc82 intopython:mainOct 16, 2025
43 checks passed
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@encukouencukouencukou approved these changes

@ronaldoussorenronaldoussorenAwaiting requested review from ronaldoussoren

+1 more reviewer

@nijelnijelnijel left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Labels

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

3 participants

@serhiy-storchaka@encukou@nijel

[8]ページ先頭

©2009-2025 Movatter.jp