A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/python/cpython/commit/d315722564927c7202dd6e111dc79eaf14240b0d below:

Fix quadratic time idna decoding. (#99092) · python/cpython@d315722 · GitHub

File tree Expand file treeCollapse file tree 3 files changed

+45

-17

lines changed

Filter options

Expand file treeCollapse file tree 3 files changed

+45

-17

lines changed Original file line number Diff line number Diff line change

@@ -39,23 +39,21 @@ def nameprep(label):

39 39 40 40

# Check bidi

41 41

RandAL = [stringprep.in_table_d1(x) for x in label]

42 -

for c in RandAL:

43 -

if c:

44 -

# There is a RandAL char in the string. Must perform further

45 -

# tests:

46 -

# 1) The characters in section 5.8 MUST be prohibited.

47 -

# This is table C.8, which was already checked

48 -

# 2) If a string contains any RandALCat character, the string

49 -

# MUST NOT contain any LCat character.

50 -

if any(stringprep.in_table_d2(x) for x in label):

51 -

raise UnicodeError("Violation of BIDI requirement 2")

52 - 53 -

# 3) If a string contains any RandALCat character, a

54 -

# RandALCat character MUST be the first character of the

55 -

# string, and a RandALCat character MUST be the last

56 -

# character of the string.

57 -

if not RandAL[0] or not RandAL[-1]:

58 -

raise UnicodeError("Violation of BIDI requirement 3")

42 +

if any(RandAL):

43 +

# There is a RandAL char in the string. Must perform further

44 +

# tests:

45 +

# 1) The characters in section 5.8 MUST be prohibited.

46 +

# This is table C.8, which was already checked

47 +

# 2) If a string contains any RandALCat character, the string

48 +

# MUST NOT contain any LCat character.

49 +

if any(stringprep.in_table_d2(x) for x in label):

50 +

raise UnicodeError("Violation of BIDI requirement 2")

51 +

# 3) If a string contains any RandALCat character, a

52 +

# RandALCat character MUST be the first character of the

53 +

# string, and a RandALCat character MUST be the last

54 +

# character of the string.

55 +

if not RandAL[0] or not RandAL[-1]:

56 +

raise UnicodeError("Violation of BIDI requirement 3")

59 57 60 58

return label

61 59

@@ -103,6 +101,16 @@ def ToASCII(label):

103 101

raise UnicodeError("label empty or too long")

104 102 105 103

def ToUnicode(label):

104 +

if len(label) > 1024:

105 +

# Protection from https://github.com/python/cpython/issues/98433.

106 +

# https://datatracker.ietf.org/doc/html/rfc5894#section-6

107 +

# doesn't specify a label size limit prior to NAMEPREP. But having

108 +

# one makes practical sense.

109 +

# This leaves ample room for nameprep() to remove Nothing characters

110 +

# per https://www.rfc-editor.org/rfc/rfc3454#section-3.1 while still

111 +

# preventing us from wasting time decoding a big thing that'll just

112 +

# hit the actual <= 63 length limit in Step 6.

113 +

raise UnicodeError("label way too long")

106 114

# Step 1: Check for ASCII

107 115

if isinstance(label, bytes):

108 116

pure_ascii = True

Original file line number Diff line number Diff line change

@@ -1552,6 +1552,12 @@ def test_builtin_encode(self):

1552 1552

self.assertEqual("pyth\xf6n.org".encode("idna"), b"xn--pythn-mua.org")

1553 1553

self.assertEqual("pyth\xf6n.org.".encode("idna"), b"xn--pythn-mua.org.")

1554 1554 1555 +

def test_builtin_decode_length_limit(self):

1556 +

with self.assertRaisesRegex(UnicodeError, "way too long"):

1557 +

(b"xn--016c"+b"a"*1100).decode("idna")

1558 +

with self.assertRaisesRegex(UnicodeError, "too long"):

1559 +

(b"xn--016c"+b"a"*70).decode("idna")

1560 + 1555 1561

def test_stream(self):

1556 1562

r = codecs.getreader("idna")(io.BytesIO(b"abc"))

1557 1563

r.read(3)

Original file line number Diff line number Diff line change

@@ -0,0 +1,14 @@

1 +

The IDNA codec decoder used on DNS hostnames by :mod:`socket` or :mod:`asyncio`

2 +

related name resolution functions no longer involves a quadratic algorithm.

3 +

This prevents a potential CPU denial of service if an out-of-spec excessive

4 +

length hostname involving bidirectional characters were decoded. Some protocols

5 +

such as :mod:`urllib` http ``3xx`` redirects potentially allow for an attacker

6 +

to supply such a name.

7 + 8 +

Individual labels within an IDNA encoded DNS name will now raise an error early

9 +

during IDNA decoding if they are longer than 1024 unicode characters given that

10 +

each decoded DNS label must be 63 or fewer characters and the entire decoded

11 +

DNS name is limited to 255. Only an application presenting a hostname or label

12 +

consisting primarily of :rfc:`3454` section 3.1 "Nothing" characters to be

13 +

removed would run into of this new limit. See also :rfc:`5894` section 6 and

14 +

:rfc:`3491`.

You can’t perform that action at this time.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4