Closed
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Bug report
Bug description:
Since 3.14, zipfile.is_zipfile() raises ValueError: negative seek value instead of returning False when given a file-like object such as io.BytesIO whose end of central directory record places the central directory before offset 0. A real file returns False, because the OSError from seek() is caught there; the ValueError also skips restoring the caller's file position.
import io, struct, zipfile
buf = io.BytesIO()
with zipfile.ZipFile(buf, "w") as zf:
zf.writestr("a.txt", b"hello")
data = bytearray(buf.getvalue())
struct.pack_into("<L", data, len(data) - 22 + 12, len(data)) # inflate CD size
zipfile.is_zipfile(io.BytesIO(data)) # ValueError: negative seek value -...Expected False, as for the same bytes on disk. This was introduced by gh-134250 (gh-72680).
CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux
Linked PRs
Metadata
Metadata
Assignees
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Activity
gh-161094: Fix `zipfile.is_zipfile()` raising `ValueError` on file-li…
[3.14] gh-161094: Fix `zipfile.is_zipfile()` raising `ValueError` on …
[3.15] gh-161094: Fix `zipfile.is_zipfile()` raising `ValueError` on …