Issue 25624: shutil.make_archive makes invalid directory entries (original) (raw)

Created on 2015-11-14 09:25 by gumblex, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
storedirectory.patch gumblex,2015-11-14 10:52 review
storedirectory_test.patch gumblex,2015-11-22 06:50 zipfile patch with test review
Messages (15)
msg254647 - (view) Author: Dingyuan Wang (gumblex) * Date: 2015-11-14 09:25
The _make_zipfile in shutil uses ZIP_DEFLATED compression by default, and the fix introduced by #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.
msg254648 - (view) Author: SilentGhost (SilentGhost) * (Python triager) Date: 2015-11-14 09:28
Can you provide a test?
msg254649 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-11-14 10:11
Do you want to provide a patch?
msg254650 - (view) Author: Dingyuan Wang (gumblex) * Date: 2015-11-14 10:13
$ 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+)
msg254651 - (view) Author: Dingyuan Wang (gumblex) * Date: 2015-11-14 10:52
My patch for this.
msg255054 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-11-21 12:19
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?
msg255084 - (view) Author: Dingyuan Wang (gumblex) * Date: 2015-11-22 06:50
Yes, patching zipfile is enough. I wrote a test using `unzip -t` to check the zip. ZipFile.testzip can't detect this kind of error because zlib.decompressobj(-15) will decode b'' to b'' without errors.
msg255097 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2015-11-22 12:56
New changeset e7d1df56f70b by Serhiy Storchaka in branch '3.4': Issue #25624: ZipFile now always writes a ZIP_STORED header for directory https://hg.python.org/cpython/rev/e7d1df56f70b New changeset 0f8d426e0d0c by Serhiy Storchaka in branch '3.5': Issue #25624: ZipFile now always writes a ZIP_STORED header for directory https://hg.python.org/cpython/rev/0f8d426e0d0c New changeset 09ed44192995 by Serhiy Storchaka in branch 'default': Issue #25624: ZipFile now always writes a ZIP_STORED header for directory https://hg.python.org/cpython/rev/09ed44192995 New changeset de5582c569ff by Serhiy Storchaka in branch '2.7': Issue #25624: ZipFile now always writes a ZIP_STORED header for directory https://hg.python.org/cpython/rev/de5582c569ff
msg255098 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-11-22 13:01
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.
msg255124 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2015-11-23 03:05
New changeset 43208b0f2535 by Benjamin Peterson in branch '2.7': Issue #25624: ZipFile now always writes a ZIP_STORED header for directory entries. Patch by Dingyuan Wang. https://hg.python.org/cpython/rev/43208b0f2535
msg255128 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-11-23 06:29
Thank you Benjamin.
msg255135 - (view) Author: Larry Hastings (larry) * (Python committer) Date: 2015-11-23 07:28
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.
msg255137 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-11-23 08:02
Larry, I think this patch is enough important to go into 3.5.1 final. It fixes a regression in common operation.
msg256054 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-12-07 08:43
Larry, is this fix included in 3.5.1?
msg256720 - (view) Author: Larry Hastings (larry) * (Python committer) Date: 2015-12-19 07:59
Like I said--no.
History
Date User Action Args
2022-04-11 14:58:23 admin set nosy: + ned.deilygithub: 69810
2015-12-19 08:11:01 serhiy.storchaka set status: open -> closed
2015-12-19 07:59:54 larry set messages: +
2015-12-07 08:43:09 serhiy.storchaka set messages: +
2015-12-07 08:39:47 serhiy.storchaka set status: closed -> open
2015-11-23 08:02:35 serhiy.storchaka set messages: +
2015-11-23 07:28:30 larry set messages: +
2015-11-23 06:29:30 serhiy.storchaka set status: open -> closedresolution: fixedmessages: + stage: test needed -> resolved
2015-11-23 03:05:38 python-dev set messages: +
2015-11-22 13:01:06 serhiy.storchaka set priority: normal -> release blockernosy: + benjamin.peterson, larrymessages: +
2015-11-22 12:56:55 python-dev set nosy: + python-devmessages: +
2015-11-22 06:50:11 gumblex set files: + storedirectory_test.patchmessages: +
2015-11-21 12:19:58 serhiy.storchaka set messages: + stage: needs patch -> test needed
2015-11-14 10:52:44 gumblex set files: + storedirectory.patchkeywords: + patchmessages: +
2015-11-14 10:13:26 gumblex set messages: + versions: + Python 2.7, Python 3.4
2015-11-14 10:11:22 serhiy.storchaka set keywords: + easyassignee: serhiy.storchakamessages: + stage: needs patch
2015-11-14 09:28:24 SilentGhost set nosy: + SilentGhost, tarek, serhiy.storchakamessages: + versions: + Python 3.6
2015-11-14 09:25:24 gumblex create