Skip to content

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

Merged
Yhg1s merged 1 commit into
python:3.12from
encukou:backport-ba785b8-3.12
Aug 4, 2026
Merged

[3.12] gh-149079: Fix O(n^2) canonical ordering in unicodedata.normalize() (GH-149080)#150843
Yhg1s merged 1 commit into
python:3.12from
encukou:backport-ba785b8-3.12

Conversation

@encukou

@encukou encukou commented Jun 3, 2026

Copy link
Copy Markdown
Member

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]>
@encukou encukou added needs backport to 3.10 only security fixes needs backport to 3.11 only security fixes labels Jun 4, 2026
@Yhg1s
Yhg1s merged commit d3ab945 into python:3.12 Aug 4, 2026
50 of 52 checks passed
@miss-islington-app

Copy link
Copy Markdown

Thanks @encukou for the PR, and @Yhg1s for merging it 🌮🎉.. I'm working now to backport this PR to: 3.10, 3.11.
🐍🍒⛏🤖

@bedevere-app

bedevere-app Bot commented Aug 4, 2026

Copy link
Copy Markdown

GH-155158 is a backport of this pull request to the 3.11 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.11 only security fixes label Aug 4, 2026
@bedevere-app

bedevere-app Bot commented Aug 4, 2026

Copy link
Copy Markdown

GH-155159 is a backport of this pull request to the 3.10 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.10 only security fixes label Aug 4, 2026
pablogsal pushed a commit that referenced this pull request Aug 10, 2026
…ize() (GH-149080) (GH-150843) (#155158)

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

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)
(cherry picked from commit d3ab945)

Co-authored-by: Petr Viktorin <[email protected]>
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]>
pablogsal pushed a commit that referenced this pull request Aug 10, 2026
…ize() (GH-149080) (GH-150843) (#155159)

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

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)
(cherry picked from commit d3ab945)

Co-authored-by: Petr Viktorin <[email protected]>
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]>
Co-authored-by: Hugo van Kemenade <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants