Skip to content

gh-157675: Add *limit* argument to encodings.idna.nameprep - #157682

Draft
encukou wants to merge 1 commit into
python:mainfrom
encukou:long-idna
Draft

encukou wants to merge 1 commit into
python:mainfrom
encukou:long-idna

Conversation

@encukou

@encukou encukou commented Sep 17, 2026

Copy link
Copy Markdown
Member

Add a limit argument to nameprep to allow ToASCII and ToUnicode to reject extremely large input early.
This replaces the check in #99092, while allowing any number of harmless "characters mapped to nothing" (RFC 3454 §3.1).

The default stays unlimited, to not change behaviour for users that call nameprep manually (and don't necessarily follow up with punycode).

Add a *limit* argument to nameprep to allow ToASCII and ToUnicode
to reject extremely large input early.
This replaces the check in python#99092, while allowing any number of
harmless "characters mapped to nothing" (RFC 3454 §3.1).

The default stays unlimited, to not change behaviour for users
that call nameprep manually (and don't necessarily follow up with
punycode).
@read-the-docs-community

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #34614204 | 📁 Comparing 8337557 against main (1e03154)

  🔍 Preview build  

3 files changed
± library/codecs.html
± whatsnew/3.16.html
± whatsnew/changelog.html

Comment thread Lib/encodings/idna.py
Comment thread Lib/encodings/idna.py
raise UnicodeEncodeError("idna", label, 0, len(label), "label too long")

def ToUnicode(label):
if len(label) > 1024:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This breaks protection for decoding:

u_label = ToUnicode(label)

By the time we reach nameprep we have already gone through punycode.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course I missed something obvious. Thanks; I'll fix tomorrow.

@encukou
encukou marked this pull request as draft September 17, 2026 16:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants