Issue #16037: HTTPMessage.readheaders() raises an HTTPException when more than

100 headers are read.  Adapted from patch by Jyrki Pulliainen.
This commit is contained in:
Georg Brandl 2014-09-30 14:08:04 +02:00
parent ec3c103520
commit f0746ca463
4 changed files with 18 additions and 2 deletions

View file

@ -206,6 +206,8 @@ MAXAMOUNT = 1048576
# maximal line length when calling readline().
_MAXLINE = 65536
_MAXHEADERS = 100
class HTTPMessage(email.message.Message):
# XXX The only usage of this method is in
@ -253,6 +255,8 @@ def parse_headers(fp, _class=HTTPMessage):
if len(line) > _MAXLINE:
raise LineTooLong("header line")
headers.append(line)
if len(headers) > _MAXHEADERS:
raise HTTPException("got more than %d headers" % _MAXHEADERS)
if line in (b'\r\n', b'\n', b''):
break
hstring = b''.join(headers).decode('iso-8859-1')