Skip to content

O(n²) insertion sort in unicodedata.normalize("NFC") canonical ordering #149079

Closed

Description

@sethmlarson

Bug report

Bug description:

From @ch4n3-yoon:

CPython's unicodedata.normalize("NFC") implementation uses an insertion sort for the canonical ordering step of combining characters, which exhibits O(n²) time complexity on crafted inputs. An attacker can cause denial of service by supplying a string with many consecutive combining characters whose Canonical Combining Class (CCC) values are arranged in alternating order, leading to excessive CPU consumption. A 0.5MB payload can consume over 30 seconds of CPU time.

CPython versions tested on:

CPython main branch

Operating systems tested on:

No response

Linked PRs

Activity

  1. added a commit that references this issue on Apr 27, 2026
  2. added and removed
    type-bugAn unexpected behavior, bug, or error
    on Apr 28, 2026
  3. added a commit that references this issue on Jun 2, 2026
  4. added 2 commits that reference this issue on Jun 2, 2026
  5. added a commit that references this issue on Jun 2, 2026
  6. added a commit that references this issue on Jun 2, 2026
  7. added 3 commits that reference this issue on Jun 3, 2026
  8. added a commit that references this issue on Jun 15, 2026
  9. added a commit that references this issue on Jun 17, 2026
  10. added a commit that references this issue on Aug 4, 2026
  11. added 2 commits that reference this issue on Aug 10, 2026
  12. added 4 commits that reference this issue on Sep 18, 2026
  13. added 3 commits that reference this issue on Oct 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions