summaryrefslogtreecommitdiffstats
path: root/Lib/zipfile
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2023-10-25 00:32:08 (GMT)
committerGitHub <noreply@github.com>2023-10-25 00:32:08 (GMT)
commit6f130f231b8524f1b5c8d9c4cf155e93ef01062f (patch)
tree81edf7c40cad47b3df65368f273f01a6c24b2ebe /Lib/zipfile
parenta4eb2e308d8c044aa87e560b1ddccbc804e003f1 (diff)
downloadcpython-6f130f231b8524f1b5c8d9c4cf155e93ef01062f.zip
cpython-6f130f231b8524f1b5c8d9c4cf155e93ef01062f.tar.gz
cpython-6f130f231b8524f1b5c8d9c4cf155e93ef01062f.tar.bz2
[3.12] gh-102956: Fix returning of empty byte strings after seek in zipfile … (GH-103565) (#111289)
gh-102956: Fix returning of empty byte strings after seek in zipfile … (GH-103565) (cherry picked from commit c73b0f35602abf5f283bf64266641f19bc82fce0) gh-102956: Fix returning of empty byte strings after seek in zipfile module. This was a regression in 3.12.0 due to a performance enhancement. Co-authored-by: Jokimax <77680901+Jokimax@users.noreply.github.com>
Diffstat (limited to 'Lib/zipfile')
-rw-r--r--Lib/zipfile/__init__.py10
1 files changed, 5 insertions, 5 deletions
diff --git a/Lib/zipfile/__init__.py b/Lib/zipfile/__init__.py
index 5b981d5..59d1055 100644
--- a/Lib/zipfile/__init__.py
+++ b/Lib/zipfile/__init__.py
@@ -1122,8 +1122,12 @@ class ZipExtFile(io.BufferedIOBase):
read_offset = new_pos - curr_pos
buff_offset = read_offset + self._offset
+ if buff_offset >= 0 and buff_offset < len(self._readbuffer):
+ # Just move the _offset index if the new position is in the _readbuffer
+ self._offset = buff_offset
+ read_offset = 0
# Fast seek uncompressed unencrypted file
- if self._compress_type == ZIP_STORED and self._decrypter is None and read_offset > 0:
+ elif self._compress_type == ZIP_STORED and self._decrypter is None and read_offset > 0:
# disable CRC checking after first seeking - it would be invalid
self._expected_crc = None
# seek actual file taking already buffered data into account
@@ -1134,10 +1138,6 @@ class ZipExtFile(io.BufferedIOBase):
# flush read buffer
self._readbuffer = b''
self._offset = 0
- elif buff_offset >= 0 and buff_offset < len(self._readbuffer):
- # Just move the _offset index if the new position is in the _readbuffer
- self._offset = buff_offset
- read_offset = 0
elif read_offset < 0:
# Position is before the current position. Reset the ZipExtFile
self._fileobj.seek(self._orig_compress_start)