This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: ZipFile sanity checks
Type: Stage: resolved
Components: Library (Lib) Versions: Python 3.4, Python 3.5
process
Status: closed Resolution: duplicate
Dependencies: Superseder: Using zipfile.Path with several files prematurely closes zip
View: 40564
Assigned To: Nosy List: alanmcintyre, iritkatriel, serhiy.storchaka, twouters
Priority: normal Keywords:

Created on 2015-04-18 04:44 by Antony.Lee, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (2)
msg241396 - (view) Author: Antony Lee (Antony.Lee) * Date: 2015-04-18 04:44
ZipFile.{open,read} could raise IsADirectoryError when called on a directory entry, rather than return an empty bytes.
ZipFile.writestr could fail writing non-empty bytes to a directory entry.

Use case for open and read: I was trying to write a zip merger (taking multiple zip files and merge them into a single zip).  Unfortunately, the obvious approach (iterate on the original infolists, extract each of them and writestr them to the new ZipFile object) created invalid zip files because it'll create empty files for each directory.  Raising IsADirectoryError would have brought attention to the issue much earlier.

The suggested modification to writestr is a bit different, but also makes sense because the bytes argument is not written anywhere anyways in the case of directory entries.
msg407155 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2021-11-27 16:55
I get NotADirectory errors now, I believe they were added in issue40564.
History
Date User Action Args
2022-04-11 14:58:15adminsetgithub: 68179
2021-11-27 17:07:53Antony.Leesetnosy: - Antony.Lee
2021-11-27 16:55:03iritkatrielsetstatus: open -> closed

superseder: Using zipfile.Path with several files prematurely closes zip

nosy: + iritkatriel
messages: + msg407155
resolution: duplicate
stage: resolved
2015-04-18 07:35:23serhiy.storchakasetnosy: + twouters, alanmcintyre, serhiy.storchaka
2015-04-18 04:44:07Antony.Leecreate