File tree 3 files changed +21
-1
lines changed
Misc/NEWS.d/next/Security
3 files changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -39,6 +39,7 @@ def nameprep(label):
39
39
40
40
# Check bidi
41
41
RandAL = [stringprep .in_table_d1 (x ) for x in label ]
42
+ any_in_table_d2 = any (stringprep .in_table_d2 (x ) for x in label )
42
43
for c in RandAL :
43
44
if c :
44
45
# There is a RandAL char in the string. Must perform further
@@ -47,7 +48,7 @@ def nameprep(label):
47
48
# This is table C.8, which was already checked
48
49
# 2) If a string contains any RandALCat character, the string
49
50
# MUST NOT contain any LCat character.
50
- if any ( stringprep . in_table_d2 ( x ) for x in label ) :
51
+ if any_in_table_d2 :
51
52
raise UnicodeError ("Violation of BIDI requirement 2" )
52
53
53
54
# 3) If a string contains any RandALCat character, a
Original file line number Diff line number Diff line change 3
3
import io
4
4
import locale
5
5
import sys
6
+ import time
6
7
import unittest
7
8
import encodings
8
9
from unittest import mock
@@ -1552,6 +1553,21 @@ def test_builtin_encode(self):
1552
1553
self .assertEqual ("pyth\xf6 n.org" .encode ("idna" ), b"xn--pythn-mua.org" )
1553
1554
self .assertEqual ("pyth\xf6 n.org." .encode ("idna" ), b"xn--pythn-mua.org." )
1554
1555
1556
+ def test_builtin_decode_length_limit (self ):
1557
+ get_time = time .process_time
1558
+ if get_time () <= 0 : # some platforms like WASM lack process_time()
1559
+ get_time = time .monotonic
1560
+ # This was slow prior to GH-98433's quadratic loop being fixed.
1561
+ # Before: 12s on a rpi4 --with-pydebug. After: 0.12s
1562
+ with self .assertRaises (UnicodeError ) as ctx :
1563
+ start = get_time ()
1564
+ (b"xn--016c" + b"a" * 1000 ).decode ("idna" )
1565
+ seconds_to_decode_idna_length_fail = get_time () - start
1566
+ self .assertIn ("too long" , str (ctx .exception ))
1567
+ self .assertLess (
1568
+ elapsed_seconds , 4 ,
1569
+ msg = "idna decoding length failure took waaaay too long" )
1570
+
1555
1571
def test_stream (self ):
1556
1572
r = codecs .getreader ("idna" )(io .BytesIO (b"abc" ))
1557
1573
r .read (3 )
Original file line number Diff line number Diff line change
1
+ The IDNA codec decoder used on DNS hostnames no longer involves a quadratic
2
+ algorithm. This prevents a potential CPU denial of service if an out-of-spec
3
+ excessive length hostname involving bidirectional characters is decoded.
You can’t perform that action at this time.
0 commit comments