Skip to content

Commit

Permalink
bpo-44022: Fix httplib client deny of service with total header size …
Browse files Browse the repository at this point in the history
…check after 100
  • Loading branch information
gen-xu committed May 5, 2021
1 parent 96d5c70 commit e53f243
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Lib/http/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,9 +309,12 @@ def begin(self):
if status != CONTINUE:
break
# skip the header from the 100 response
header_total_size = 0
while True:
skip = self.fp.readline(_MAXLINE + 1)
if len(skip) > _MAXLINE:
line_length = len(skip)
header_total_size += line_length
if line_length > _MAXLINE or header_total_size > _MAXLINE:
raise LineTooLong("header line")
skip = skip.strip()
if not skip:
Expand Down
8 changes: 8 additions & 0 deletions Lib/test/test_httplib.py
Original file line number Diff line number Diff line change
Expand Up @@ -1180,6 +1180,14 @@ def test_overflowing_header_line(self):
resp = client.HTTPResponse(FakeSocket(body))
self.assertRaises(client.LineTooLong, resp.begin)

def test_overflowing_total_header_size_after_100(self):
body = (
'HTTP/1.1 100 OK\r\n'
'r\n' * 32768
)
resp = client.HTTPResponse(FakeSocket(body))
self.assertRaises(client.LineTooLong, resp.begin)

def test_overflowing_chunked_line(self):
body = (
'HTTP/1.1 200 OK\r\n'
Expand Down

0 comments on commit e53f243

Please sign in to comment.