diff -r 0ff181ca7558 Lib/nntplib.py --- a/Lib/nntplib.py Wed Dec 14 20:37:53 2016 +0100 +++ b/Lib/nntplib.py Wed Dec 14 21:56:55 2016 +0100 @@ -87,9 +87,9 @@ # maximal line length when calling readline(). This is to prevent # reading arbitrary length lines. RFC 3977 limits NNTP line length to -# 512 characters, including CRLF. We have selected 2048 just to be on +# 512 characters, including CRLF. We have selected 4096 just to be on # the safe side. -_MAXLINE = 2048 +_MAXLINE = 4096 # Exceptions raised when an error or invalid response is received @@ -429,7 +429,8 @@ """Internal: return one line from the server, stripping _CRLF. Raise EOFError if the connection is closed. Returns a bytes object.""" - line = self.file.readline(_MAXLINE +1) + line = self.file.readline() + if len(line) > _MAXLINE: raise NNTPDataError('line too long') if self.debugging > 1: @@ -468,6 +469,7 @@ """ openedFile = None + exception = None try: # If a string was passed then open a file with that name if isinstance(file, (str, bytes)): @@ -482,25 +484,35 @@ # XXX lines = None instead? terminators = (b'.' + _CRLF, b'.\n') while 1: - line = self._getline(False) - if line in terminators: - break - if line.startswith(b'..'): - line = line[1:] - file.write(line) + try: + line = self._getline(False) + except NNTPDataError as e: + exception = e + else: + if line in terminators: + break + if line.startswith(b'..'): + line = line[1:] + file.write(line) else: terminator = b'.' while 1: - line = self._getline() - if line == terminator: - break - if line.startswith(b'..'): - line = line[1:] - lines.append(line) + try: + line = self._getline() + except NNTPDataError as e: + exception = e + else: + if line == terminator: + break + if line.startswith(b'..'): + line = line[1:] + lines.append(line) finally: # If this method created the file, then it must close it if openedFile: openedFile.close() + if exception: + raise exception return resp, lines