Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.11] gh-98433: Fix quadratic time idna decoding. (GH-99092) #99222

Merged
merged 3 commits into from
Nov 8, 2022

Conversation

miss-islington
Copy link
Contributor

@miss-islington miss-islington commented Nov 8, 2022

There was an unnecessary quadratic loop in idna decoding. This restores
the behavior to linear.

(cherry picked from commit d315722)

Co-authored-by: Gregory P. Smith greg@krypto.org

There was an unnecessary quadratic loop in idna decoding. This restores
the behavior to linear.

This also adds an early length check in IDNA decoding to outright reject
huge inputs early on given the ultimate result is defined to be 63 or fewer
characters.
(cherry picked from commit d315722)

Co-authored-by: Gregory P. Smith <greg@krypto.org>
While I don't think anyone should have reasonable code depending on
unbounded strings full of Nothing characters to silently be removed
during idna decoding... this is the conservative choice for a bugfix
backport.
@gpshead
Copy link
Member

gpshead commented Nov 8, 2022

I went with the conservative choice of not adding the upfront length check in the backports. The quadratic algorithm fix remains.

Manually inspecting Lib/encoding/punycode.py codec implementation, that looked to me like an O(NlogN) algorithm at worse for decoding, so not really a denial of service concern itself. If anyone disagrees, feel free to open a new issue with a demonstration.

@gpshead
Copy link
Member

gpshead commented Nov 8, 2022

i'm using the no-not-merge label to prevent automerge so i can manually edit the commit message.

@gpshead gpshead self-assigned this Nov 8, 2022
@gpshead gpshead merged commit a6f6c3a into python:3.11 Nov 8, 2022
@miss-islington
Copy link
Contributor Author

Thanks @miss-islington for the PR, and @gpshead for merging it 🌮🎉.. I'm working now to backport this PR to: 3.7, 3.8, 3.9, 3.10.
🐍🍒⛏🤖

@miss-islington miss-islington deleted the backport-d315722-3.11 branch November 8, 2022 02:57
@bedevere-bot
Copy link

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

@bedevere-bot bedevere-bot removed the needs backport to 3.10 only security fixes label Nov 8, 2022
@bedevere-bot
Copy link

GH-99230 is a backport of this pull request to the 3.9 branch.

@bedevere-bot bedevere-bot removed the needs backport to 3.9 only security fixes label Nov 8, 2022
miss-islington added a commit to miss-islington/cpython that referenced this pull request Nov 8, 2022
) (pythonGH-99222)

There was an unnecessary quadratic loop in idna decoding. This restores
the behavior to linear.

(cherry picked from commit d315722)

(cherry picked from commit a6f6c3a)

Co-authored-by: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Co-authored-by: Gregory P. Smith <greg@krypto.org>
@bedevere-bot
Copy link

GH-99231 is a backport of this pull request to the 3.8 branch.

@bedevere-bot
Copy link

GH-99232 is a backport of this pull request to the 3.7 branch.

miss-islington added a commit to miss-islington/cpython that referenced this pull request Nov 8, 2022
) (pythonGH-99222)

There was an unnecessary quadratic loop in idna decoding. This restores
the behavior to linear.

(cherry picked from commit d315722)

(cherry picked from commit a6f6c3a)

Co-authored-by: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Co-authored-by: Gregory P. Smith <greg@krypto.org>
@bedevere-bot
Copy link

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

@bedevere-bot
Copy link

GH-99230 is a backport of this pull request to the 3.9 branch.

miss-islington added a commit to miss-islington/cpython that referenced this pull request Nov 8, 2022
) (pythonGH-99222)

There was an unnecessary quadratic loop in idna decoding. This restores
the behavior to linear.

(cherry picked from commit d315722)

(cherry picked from commit a6f6c3a)

Co-authored-by: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Co-authored-by: Gregory P. Smith <greg@krypto.org>
@bedevere-bot
Copy link

GH-99231 is a backport of this pull request to the 3.8 branch.

@bedevere-bot
Copy link

GH-99232 is a backport of this pull request to the 3.7 branch.

miss-islington added a commit that referenced this pull request Nov 8, 2022
There was an unnecessary quadratic loop in idna decoding. This restores
the behavior to linear.

(cherry picked from commit d315722)

(cherry picked from commit a6f6c3a)

Co-authored-by: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Co-authored-by: Gregory P. Smith <greg@krypto.org>
ambv pushed a commit that referenced this pull request Nov 10, 2022
… (GH-99231)

There was an unnecessary quadratic loop in idna decoding. This restores
the behavior to linear.

(cherry picked from commit d315722)
(cherry picked from commit a6f6c3a)

Co-authored-by: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Co-authored-by: Gregory P. Smith <greg@krypto.org>
ambv pushed a commit that referenced this pull request Nov 10, 2022
… (#99230)

There was an unnecessary quadratic loop in idna decoding. This restores
the behavior to linear.

(cherry picked from commit d315722)
(cherry picked from commit a6f6c3a)

Co-authored-by: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Co-authored-by: Gregory P. Smith <greg@krypto.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug An unexpected behavior, bug, or error type-security A security issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants