diff --git a/Lib/zipfile/__init__.py b/Lib/zipfile/__init__.py index 6907ae6d5b7464..dc557eaf00b3c6 100644 --- a/Lib/zipfile/__init__.py +++ b/Lib/zipfile/__init__.py @@ -1162,13 +1162,16 @@ def seek(self, offset, whence=os.SEEK_SET): self._offset = buff_offset read_offset = 0 # Fast seek uncompressed unencrypted file - elif 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: # disable CRC checking after first seeking - it would be invalid self._expected_crc = None # seek actual file taking already buffered data into account read_offset -= len(self._readbuffer) - self._offset self._fileobj.seek(read_offset, os.SEEK_CUR) self._left -= read_offset + self._compress_left -= read_offset + if self._eof and read_offset < 0: + self._eof = False read_offset = 0 # flush read buffer self._readbuffer = b'' diff --git a/Misc/NEWS.d/next/Library/2024-12-20-16-27-47.gh-issue-128131.ZK_0MM.rst b/Misc/NEWS.d/next/Library/2024-12-20-16-27-47.gh-issue-128131.ZK_0MM.rst new file mode 100644 index 00000000000000..7ca2ef2bed9e75 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2024-12-20-16-27-47.gh-issue-128131.ZK_0MM.rst @@ -0,0 +1 @@ +Allow random access uncompressed unencrypted ZipExtFile