summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2005-09-29 20:16:07 (GMT)
committerGeorg Brandl <georg@python.org>2005-09-29 20:16:07 (GMT)
commit80ba8e85490515c293959a4196cbd99b1b3819a2 (patch)
treee4d022b8ad033e2128a52a9db46315caf80481a8
parente677adc43acf9176ffe81b9956aeb7a643258239 (diff)
downloadcpython-80ba8e85490515c293959a4196cbd99b1b3819a2.zip
cpython-80ba8e85490515c293959a4196cbd99b1b3819a2.tar.gz
cpython-80ba8e85490515c293959a4196cbd99b1b3819a2.tar.bz2
bug [ 1296004 ] MemoryError in httplib
-rw-r--r--Lib/httplib.py11
-rw-r--r--Misc/NEWS3
2 files changed, 10 insertions, 4 deletions
diff --git a/Lib/httplib.py b/Lib/httplib.py
index e017cdf..5c82edd 100644
--- a/Lib/httplib.py
+++ b/Lib/httplib.py
@@ -153,6 +153,9 @@ HTTP_VERSION_NOT_SUPPORTED = 505
INSUFFICIENT_STORAGE = 507
NOT_EXTENDED = 510
+# maximal amount of data to read at one time in _safe_read
+MAXAMOUNT = 1048576
+
class HTTPMessage(mimetools.Message):
def addheader(self, key, value):
@@ -541,14 +544,14 @@ class HTTPResponse:
reading. If the bytes are truly not available (due to EOF), then the
IncompleteRead exception can be used to detect the problem.
"""
- s = ''
+ s = []
while amt > 0:
- chunk = self.fp.read(amt)
+ chunk = self.fp.read(min(amt, MAXAMOUNT))
if not chunk:
raise IncompleteRead(s)
- s += chunk
+ s.append(chunk)
amt -= len(chunk)
- return s
+ return ''.join(s)
def getheader(self, name, default=None):
if self.msg is None:
diff --git a/Misc/NEWS b/Misc/NEWS
index 9703f69..ec70b95 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -242,6 +242,9 @@ Extension Modules
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
to get the correct encoding.