Do not read more than the maximum number of bytes in a valid response header.

This commit is contained in:
Solderpunk 2020-05-31 18:33:32 +02:00
parent d5ed0c5d7a
commit 2fd8fe919b
1 changed files with 3 additions and 3 deletions

View File

@ -365,9 +365,9 @@ you'll be able to transparently follow links to Gopherspace!""")
else:
address, f = self._send_request(gi)
# Spec dictates <META> should not exceed 1024 bytes
# but does not dictate a total maximum header length.
header = f.readline(2048)
# Spec dictates <META> should not exceed 1024 bytes,
# so maximum valid header length is 1027 bytes.
header = f.readline(1027)
header = header.decode("UTF-8")
if not header or header[-1] != '\n':
raise RuntimeError("Received invalid header from server!")