The ZipFile documentation says: > If allowZip64 is True (the default) zipfile will create ZIP files that > use the ZIP64 extensions when the zipfile is larger than 2 GiB. If it > is false zipfile will raise an exception when the ZIP file would > require ZIP64 extensions. ZipFile.close() will write ZIP64 central directory records if e.g. a member's local file header starts at an offset > 2 GB, or if there are more than 65535 files in the archive. It will do this even if allowZip64 is False, whereas the documentation implies that it should raise an exception in that case.
An offset is checked in write() and writestr() methods and an exception is raised if an offset is >= 2 GiB and ZIP64 extension is not allowed. I don't see a possibility for a bug.
Here are the cases where close() will generate a ZIP64 archive and an exception will never be raised: 1. There are more than 65535 files in the archive. 2. The start of the central directory is at > 2 GB. 3. The central directory size is > 2 GB. #1 could be checked from write/writestr. #2 could possibly be checked from write/writestr by looking at the file offset after writing the compressed data. #3 cannot be checked until close, but I'm not sure if it can ever occur without triggering one of the other checks first.
Thank you Benjamin for explanation. Here is a patch which adds all three required checks in the close() method and adds a check for files count in write methods. Implementing other checks in write methods is too laborious. As far as test_zipfile64 is disabled, for manual testing you need temporary comment out the "support.requires()" statement and run only selected tests: ./python -m test.regrtest -v -m OtherTests test_zipfile64