diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2022-11-10 15:57:41 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-10 15:57:41 (GMT) |
commit | c09dba57cfbbf74273ce44b1f48f71b46806605c (patch) | |
tree | ff19ab0812ea77de71e7ffafb6578ce4c0f95c04 /Lib/test/test_codecs.py | |
parent | b43496c01a554cf41ae654a0379efae18609ad39 (diff) | |
download | cpython-c09dba57cfbbf74273ce44b1f48f71b46806605c.zip cpython-c09dba57cfbbf74273ce44b1f48f71b46806605c.tar.gz cpython-c09dba57cfbbf74273ce44b1f48f71b46806605c.tar.bz2 |
[3.9] gh-98433: Fix quadratic time idna decoding. (GH-99092) (GH-99222) (#99230)
There was an unnecessary quadratic loop in idna decoding. This restores
the behavior to linear.
(cherry picked from commit d315722564927c7202dd6e111dc79eaf14240b0d)
(cherry picked from commit a6f6c3a3d6f2b580f2d87885c9b8a9350ad7bf15)
Co-authored-by: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Co-authored-by: Gregory P. Smith <greg@krypto.org>
Diffstat (limited to 'Lib/test/test_codecs.py')
-rw-r--r-- | Lib/test/test_codecs.py | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/Lib/test/test_codecs.py b/Lib/test/test_codecs.py index fc50e70d..3520cc0 100644 --- a/Lib/test/test_codecs.py +++ b/Lib/test/test_codecs.py @@ -1532,6 +1532,12 @@ class IDNACodecTest(unittest.TestCase): self.assertEqual("pyth\xf6n.org".encode("idna"), b"xn--pythn-mua.org") self.assertEqual("pyth\xf6n.org.".encode("idna"), b"xn--pythn-mua.org.") + def test_builtin_decode_length_limit(self): + 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") + def test_stream(self): r = codecs.getreader("idna")(io.BytesIO(b"abc")) r.read(3) |