summaryrefslogtreecommitdiffstats
path: root/Lib/zipfile.py
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2010-09-12 14:51:20 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2010-09-12 14:51:20 (GMT)
commit6464d5ffdc6ee54f023c6230f1633debf183815f (patch)
tree3efb844f24e15fcd80151ac2d8e9a56e5ed92f9a /Lib/zipfile.py
parent0b9489d21daec1f5f45a95194423724836192edd (diff)
downloadcpython-6464d5ffdc6ee54f023c6230f1633debf183815f.zip
cpython-6464d5ffdc6ee54f023c6230f1633debf183815f.tar.gz
cpython-6464d5ffdc6ee54f023c6230f1633debf183815f.tar.bz2
Issue #9837: The read() method of ZipExtFile objects (as returned by
ZipFile.open()) could return more bytes than requested.
Diffstat (limited to 'Lib/zipfile.py')
-rw-r--r--Lib/zipfile.py15
1 files changed, 9 insertions, 6 deletions
diff --git a/Lib/zipfile.py b/Lib/zipfile.py
index c47c3cc..bcdb2b8 100644
--- a/Lib/zipfile.py
+++ b/Lib/zipfile.py
@@ -564,17 +564,20 @@ class ZipExtFile(io.BufferedIOBase):
"""Read and return up to n bytes.
If the argument is omitted, None, or negative, data is read and returned until EOF is reached..
"""
-
buf = b''
- while n < 0 or n is None or n > len(buf):
- data = self.read1(n)
+ if n is None:
+ n = -1
+ while True:
+ if n < 0:
+ data = self.read1(n)
+ elif n > len(buf):
+ data = self.read1(n - len(buf))
+ else:
+ return buf
if len(data) == 0:
return buf
-
buf += data
- return buf
-
def _update_crc(self, newdata, eof):
# Update the CRC using the given data.
if self._expected_crc is None: