mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
gh-102956: Fix returning of empty byte strings after seek in zipfile … (#103565)
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.
This commit is contained in:
parent
e5168ff3f8
commit
c73b0f3560
3 changed files with 22 additions and 5 deletions
|
@ -1136,8 +1136,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
|
||||
|
@ -1148,10 +1152,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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue