New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
shutil.make_archive makes invalid directory entries #69810
Comments
The _make_zipfile in shutil uses ZIP_DEFLATED compression by default, and the fix introduced by bpo-24982 adds directory entries. In zipfile.ZipFile.write, directories is added as 0 file_size, 0 compress_size, regardless of the compression method. Deflate will compress an empty string as \x03\x00, thus the directory entries become incorrect. The command line interface of zipfile is correct. Shutil can be fixed as zipfile.main. As a directory entry with compression methods other than ZIP_STORED is meaningless, zipfile.write and (maybe) zipfile.writestr should always write a ZIP_STORED header for directory entries to avoid the above problem occuring by programming mistakes. |
Can you provide a test? |
Do you want to provide a patch? |
$ mkdir foo; touch foo/a.txt; python3 -c "import shutil; shutil.make_archive('foo', 'zip', base_dir='foo')"; unzip -t foo.zip
Archive: foo.zip
testing: foo/
error: invalid compressed data to inflate
testing: foo/a.txt OK
At least one error was detected in foo.zip. (This affects 2.7, 3.4+) |
My patch for this. |
Could you add a test Dingyuan? You can take test_zipfile_vs_zip in test_shutil as an example. The patch changes both shutil and zipfile. Aren't only changes to zipfile needed? |
Yes, patching zipfile is enough. I wrote a test using |
New changeset e7d1df56f70b by Serhiy Storchaka in branch '3.4': New changeset 0f8d426e0d0c by Serhiy Storchaka in branch '3.5': New changeset 09ed44192995 by Serhiy Storchaka in branch 'default': New changeset de5582c569ff by Serhiy Storchaka in branch '2.7': |
Thank you for your contribution Dingyuan. Benjamin, I think this fix should be in 2.7.11. It was a regression in 2.7.11 that had made shutil.make_archive() unusable with the zip format. |
New changeset 43208b0f2535 by Benjamin Peterson in branch '2.7': |
Thank you Benjamin. |
This change didn't make it into 3.5.1. It will be released with 3.5.2. I've already updated the Misc/NEWS entry. |
Larry, I think this patch is enough important to go into 3.5.1 final. It fixes a regression in common operation. |
Larry, is this fix included in 3.5.1? |
Like I said--no. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: