]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
backport bug [ 1296004 ] MemoryError in httplib
authorGeorg Brandl <georg@python.org>
Thu, 29 Sep 2005 20:16:12 +0000 (20:16 +0000)
committerGeorg Brandl <georg@python.org>
Thu, 29 Sep 2005 20:16:12 +0000 (20:16 +0000)
Lib/httplib.py
Misc/NEWS

index e017cdfcd519e4df19270e2d9b1c23ae4c095a06..5c82edd8969725058c919df0b7ed8b8da76afb89 100644 (file)
@@ -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:
index 5c054e0d2d6102568c9151f53071228ad109a615..d2088cd88cb6db55cca264014ccf3b101fc8445e 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -14,6 +14,12 @@ Extension Modules
 
 - Fix parse errors in the readline module when compiling without threads.
 
+Library
+-------
+
+- Bug #1296004: httplib.py: Limit maximal amount of data read from the
+  socket to avoid a MemoryError on Windows.
+
 
 What's New in Python 2.4.2 final?
 =================================