Skip to content

gh-161094: Fix zipfile.is_zipfile() raising ValueError on file-like objects - #161095

Merged
gpshead merged 1 commit into
python:mainfrom
gpshead:zipfile-is-zipfile-negative-seek
Nov 1, 2026
Merged

gpshead merged 1 commit into
python:mainfrom
gpshead:zipfile-is-zipfile-negative-seek

Conversation

@gpshead

@gpshead gpshead commented Nov 1, 2026 •

Copy link
Copy Markdown
Member

Skip the central directory check in zipfile.is_zipfile() when the computed start of the central directory is negative, mirroring the "Bad offset for central directory" check in ZipFile. Previously the seek raised ValueError for in-memory file objects such as io.BytesIO, which is_zipfile() does not catch, while real files raised a caught OSError. The disk-number check is left alone; gh-155814 deals with that separately.

Fixes #161094

…ects

Return False instead of seeking to a negative offset when the end of
central directory record places the central directory before the start
of the file.
@gpshead gpshead added needs backport to 3.14 bugs and security fixes needs backport to 3.15 bugs and security fixes labels Nov 1, 2026
@gpshead gpshead self-assigned this Nov 1, 2026
@gpshead
gpshead marked this pull request as ready for review November 1, 2026 17:51
@gpshead
gpshead enabled auto-merge (squash) November 1, 2026 17:52
@gpshead
gpshead merged commit 2789841 into python:main Nov 1, 2026
62 checks passed
@miss-islington-app

Copy link
Copy Markdown

Thanks @gpshead for the PR 🌮🎉.. I'm working now to backport this PR to: 3.14, 3.15.
🐍🍒⛏🤖

@bedevere-app

bedevere-app Bot commented Nov 1, 2026

Copy link
Copy Markdown

GH-161120 is a backport of this pull request to the 3.15 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 bugs and security fixes label Nov 1, 2026
@bedevere-app

bedevere-app Bot commented Nov 1, 2026

Copy link
Copy Markdown

GH-161121 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Nov 1, 2026
gpshead added a commit that referenced this pull request Nov 1, 2026
…file-like objects (GH-161095) (#161121)

Return False instead of seeking to a negative offset when the end of
central directory record places the central directory before the start
of the file.

(cherry picked from commit 2789841)
gpshead added a commit that referenced this pull request Nov 1, 2026
…file-like objects (GH-161095) (#161120)

Return False instead of seeking to a negative offset when the end of
central directory record places the central directory before the start
of the file.

(cherry picked from commit 2789841)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

zipfile.is_zipfile() raises ValueError for file-like objects with a negative central directory offset

1 participant