]> granicus.if.org Git - python/commitdiff
Issue #20048: Fixed ZipExtFile.peek() when it is called on the boundary of
authorSerhiy Storchaka <storchaka@gmail.com>
Sat, 21 Dec 2013 21:51:15 +0000 (23:51 +0200)
committerSerhiy Storchaka <storchaka@gmail.com>
Sat, 21 Dec 2013 21:51:15 +0000 (23:51 +0200)
the uncompress buffer and read() goes through more than one readbuffer.

This is partial backport of changeset 028e8e0b03e8.

Lib/zipfile.py
Misc/NEWS

index 6639317537bbf7d95c830553b6124dbf24849bb4..82d240f46693b7bf6b545dde85ac70b4b26f8705 100644 (file)
@@ -606,7 +606,11 @@ class ZipExtFile(io.BufferedIOBase):
         """Returns buffered bytes without advancing the position."""
         if n > len(self._readbuffer) - self._offset:
             chunk = self.read(n)
-            self._offset -= len(chunk)
+            if len(chunk) > self._offset:
+                self._readbuffer = chunk + self._readbuffer[self._offset:]
+                self._offset = 0
+            else:
+                self._offset -= len(chunk)
 
         # Return up to 512 bytes to reduce allocation overhead for tight loops.
         return self._readbuffer[self._offset: self._offset + 512]
index 3efaa741de756469d92bbb75fb168c8aa2d6c682..aed2112c9faab783dc9c97865db61968a2181e83 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -27,6 +27,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #20048: Fixed ZipExtFile.peek() when it is called on the boundary of
+  the uncompress buffer and read() goes through more than one readbuffer.
+
 - Issue #20034: Updated alias mapping to most recent locale.alias file
   from X.org distribution using makelocalealias.py.