Skip to content

[3.11] gh-149079: Fix O(n^2) canonical ordering in unicodedata.normalize() (GH-149080) - #151570

Closed
tomcruiseqi wants to merge 1 commit into
python:3.11from
tomcruiseqi:backport-149079-3.11
Closed

[3.11] gh-149079: Fix O(n^2) canonical ordering in unicodedata.normalize() (GH-149080)#151570
tomcruiseqi wants to merge 1 commit into
python:3.11from
tomcruiseqi:backport-149079-3.11

Conversation

@tomcruiseqi

Copy link
Copy Markdown

Replace the insertion sort used for canonical ordering of combining
characters with a hybrid approach: insertion sort for short runs (< 20)
and counting sort for longer runs, reducing worst-case complexity from
O(n^2) to O(n). This prevents denial of service via crafted Unicode
strings with many combining characters in alternating CCC order.
(cherry picked from commit 991224b)

Co-authored-by: Seth Larson [email protected]
Co-authored-by: ch4n3-yoon [email protected]
Co-authored-by: Seokchan Yoon [email protected]
Co-authored-by: Stan Ulbrych [email protected]
Co-authored-by: Bénédikt Tran [email protected]
Co-authored-by: Serhiy Storchaka [email protected]
Co-authored-by: Maurycy Pawłowski-Wieroński [email protected]

…normalize() (pythonGH-149080)

Replace the insertion sort used for canonical ordering of combining
characters with a hybrid approach: insertion sort for short runs (< 20)
and counting sort for longer runs, reducing worst-case complexity from
O(n^2) to O(n). This prevents denial of service via crafted Unicode
strings with many combining characters in alternating CCC order.
(cherry picked from commit 991224b)

Co-authored-by: Seth Larson <[email protected]>
Co-authored-by: ch4n3-yoon <[email protected]>
Co-authored-by: Seokchan Yoon <[email protected]>
Co-authored-by: Stan Ulbrych <[email protected]>
Co-authored-by: Bénédikt Tran <[email protected]>
Co-authored-by: Serhiy Storchaka <[email protected]>
Co-authored-by: Maurycy Pawłowski-Wieroński <[email protected]>
@StanFromIreland

Copy link
Copy Markdown
Member

We were waiting for these as Bedevere can create them from #150843

Were there conflicts you had to fix for these?

@tomcruiseqi

Copy link
Copy Markdown
Author

Right now, there is no conflicts

@tomcruiseqi tomcruiseqi closed this Jul 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants