10000 [3.11] gh-98433: Fix quadratic time idna decoding. (GH-99092) by miss-islington · Pull Request #99222 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

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

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

Merged
merged 3 commits into from
Nov 8, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Remove the upfront length check in the backports.
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.
  • Loading branch information
gpshead committed Nov 8, 2022
commit 72ea7f80c7b9defcf8fbac8d01cf1c856f751440
10 changes: 0 additions & 10 deletions Lib/encodings/idna.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,6 @@ def ToASCII(label):
raise UnicodeError("label empty or too long")

def ToUnicode(label):
if len(label) > 1024:
# Protection from https://github.com/python/cpython/issues/98433.
# https://datatracker.ietf.org/doc/html/rfc5894#section-6
# doesn't specify a label size limit prior to NAMEPREP. But having
# one makes practical sense.
# This leaves ample room for nameprep() to remove Nothing characters
# per https://www.rfc-editor.org/rfc/rfc3454#section-3.1 while still
# preventing us from wasting time decoding a big thing that'll just
# hit the actual <= 63 length limit in Step 6.
raise UnicodeError("label way too long")
# Step 1: Check for ASCII
if isinstance(label, bytes):
pure_ascii = True
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_codecs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1554,7 +1554,7 @@ def test_builtin_encode(self):
self.assertEqual("pyth\xf6n.org.".encode("idna"), b"xn--pythn-mua.org.")

def test_builtin_decode_length_limit(self):
with self.assertRaisesRegex(UnicodeError, "way too long"):
with self.assertRaisesRegex(UnicodeError, "too long"):
(b"xn--016c"+b"a"*1100).decode("idna")
with self.assertRaisesRegex(UnicodeError, "too long"):
(b"xn--016c"+b"a"*70).decode("idna")
Expand Down
0