Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Ensure that zipfile.is_zipfile does not modify a file object.
  • Loading branch information
picnixz committed Jul 29, 2024
commit 4989d502c2179f0dbcd513d95eb9eb445077c559
2 changes: 2 additions & 0 deletions Lib/zipfile/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,9 @@ def is_zipfile(filename):
result = False
try:
if hasattr(filename, "read"):
pos = filename.tell()
result = _check_zipfile(fp=filename)
filename.seek(pos)
Comment on lines +244 to +246
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm guessing that a user will never call is_zipfile on a non-seekable stream (e.g. a web response stream)... but if they did, this change would break those cases. Oh, I just checked, and the current check already relies on a seekable fp, so this change has no effect on that behavior.

else:
with open(filename, "rb") as fp:
result = _check_zipfile(fp)
Expand Down