Commit 80ba8e85 authored by Georg Brandl's avatar Georg Brandl

bug [ 1296004 ] MemoryError in httplib

parent e677adc4
...@@ -153,6 +153,9 @@ HTTP_VERSION_NOT_SUPPORTED = 505 ...@@ -153,6 +153,9 @@ HTTP_VERSION_NOT_SUPPORTED = 505
INSUFFICIENT_STORAGE = 507 INSUFFICIENT_STORAGE = 507
NOT_EXTENDED = 510 NOT_EXTENDED = 510
# maximal amount of data to read at one time in _safe_read
MAXAMOUNT = 1048576
class HTTPMessage(mimetools.Message): class HTTPMessage(mimetools.Message):
def addheader(self, key, value): def addheader(self, key, value):
...@@ -541,14 +544,14 @@ class HTTPResponse: ...@@ -541,14 +544,14 @@ class HTTPResponse:
reading. If the bytes are truly not available (due to EOF), then the reading. If the bytes are truly not available (due to EOF), then the
IncompleteRead exception can be used to detect the problem. IncompleteRead exception can be used to detect the problem.
""" """
s = '' s = []
while amt > 0: while amt > 0:
chunk = self.fp.read(amt) chunk = self.fp.read(min(amt, MAXAMOUNT))
if not chunk: if not chunk:
raise IncompleteRead(s) raise IncompleteRead(s)
s += chunk s.append(chunk)
amt -= len(chunk) amt -= len(chunk)
return s return ''.join(s)
def getheader(self, name, default=None): def getheader(self, name, default=None):
if self.msg is None: if self.msg is None:
......
...@@ -242,6 +242,9 @@ Extension Modules ...@@ -242,6 +242,9 @@ Extension Modules
Library Library
------- -------
- Bug #1296004: httplib.py: Limit maximal amount of data read from the
socket to avoid a MemoryError on Windows.
- Patch #1166948: locale.py: Prefer LC_ALL, LC_CTYPE and LANG over LANGUAGE - Patch #1166948: locale.py: Prefer LC_ALL, LC_CTYPE and LANG over LANGUAGE
to get the correct encoding. to get the correct encoding.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment