Skip to content

Commit 8ff7107

Browse files
committed
Reject Content-Length longer than 4300 digits
1 parent 31e626c commit 8ff7107

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

Diff for: h11/_headers.py

+8
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212
except ImportError:
1313
from typing_extensions import Literal # type: ignore
1414

15+
try:
16+
from sys import get_int_max_str_digits
17+
except ImportError:
18+
def get_int_max_str_digits():
19+
return 4300 # CPython default
20+
1521

1622
# Facts
1723
# -----
@@ -173,6 +179,8 @@ def normalize_and_validate(
173179
raise LocalProtocolError("conflicting Content-Length headers")
174180
value = lengths.pop()
175181
validate(_content_length_re, value, "bad Content-Length")
182+
if len(value) > get_int_max_str_digits():
183+
raise LocalProtocolError("bad Content-Length")
176184
if seen_content_length is None:
177185
seen_content_length = value
178186
new_headers.append((raw_name, name, value))

Diff for: h11/tests/test_headers.py

+2
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ def test_normalize_and_validate() -> None:
7474
)
7575
with pytest.raises(LocalProtocolError):
7676
normalize_and_validate([("Content-Length", "1 , 1,2")])
77+
with pytest.raises(LocalProtocolError):
78+
normalize_and_validate([("Content-Length", "1" * 4301)])
7779

7880
# transfer-encoding
7981
assert normalize_and_validate([("Transfer-Encoding", "chunked")]) == [

0 commit comments

Comments
 (0)