- Issue #16037: HTTPMessage.readheaders() raises an HTTPException when more
than 100 headers are read. Adapted from patch by Jyrki Pulliainen.
diff --git a/Lib/httplib.py b/Lib/httplib.py
index 680e875..8c2eab6 100644
--- a/Lib/httplib.py
+++ b/Lib/httplib.py
@@ -211,6 +211,10 @@
# maximal amount of data to read at one time in _safe_read
MAXAMOUNT = 1048576
+# maximum amount of headers accepted
+_MAXHEADERS = 100
+
+
class HTTPMessage(mimetools.Message):
def addheader(self, key, value):
@@ -267,6 +271,8 @@
elif self.seekable:
tell = self.fp.tell
while True:
+ if len(hlist) > _MAXHEADERS:
+ raise HTTPException("got more than %d headers" % _MAXHEADERS)
if tell:
try:
startofline = tell()
@@ -1203,6 +1209,7 @@
self.args = line,
self.line = line
+
# for backwards compatibility
error = HTTPException