File tree 2 files changed +6
-0
lines changed
2 files changed +6
-0
lines changed Original file line number Diff line number Diff line change 12
12
except ImportError :
13
13
from typing_extensions import Literal # type: ignore
14
14
15
+ CONTENT_LENGTH_MAX_DIGITS = 20 # allow up to 100_000_000TB
16
+
15
17
16
18
# Facts
17
19
# -----
@@ -173,6 +175,8 @@ def normalize_and_validate(
173
175
raise LocalProtocolError ("conflicting Content-Length headers" )
174
176
value = lengths .pop ()
175
177
validate (_content_length_re , value , "bad Content-Length" )
178
+ if len (value ) > CONTENT_LENGTH_MAX_DIGITS :
179
+ raise LocalProtocolError ("bad Content-Length" )
176
180
if seen_content_length is None :
177
181
seen_content_length = value
178
182
new_headers .append ((raw_name , name , value ))
Original file line number Diff line number Diff line change @@ -74,6 +74,8 @@ def test_normalize_and_validate() -> None:
74
74
)
75
75
with pytest .raises (LocalProtocolError ):
76
76
normalize_and_validate ([("Content-Length" , "1 , 1,2" )])
77
+ with pytest .raises (LocalProtocolError ):
78
+ normalize_and_validate ([("Content-Length" , "1" * 21 )]) # 1 billion TB
77
79
78
80
# transfer-encoding
79
81
assert normalize_and_validate ([("Transfer-Encoding" , "chunked" )]) == [
You can’t perform that action at this time.
0 commit comments