classification
Title: Make zipimport work with zipfile containing comments
Type: enhancement Stage: patch review
Components: Interpreter Core Versions: Python 3.4
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Dima.Tisnek, brett.cannon, dsamersoff, eric.snow, georg.brandl, gregory.p.smith, grubert, ncoghlan, peter.otten, rfk, serhiy.storchaka, terry.reedy, theller, twouters
Priority: normal Keywords: patch

Created on 2009-05-06 16:49 by dsamersoff, last changed 2014-09-01 16:36 by serhiy.storchaka.

Files
File name Uploaded Description Edit
testcase.zip dsamersoff, 2009-05-06 16:49 Testcase zipfile with comment inside
zipimport_with_comments.patch rfk, 2010-07-13 00:26
Messages (20)
msg87340 - (view) Author: Dmitry (dsamersoff) Date: 2009-05-06 16:49
Synopsys:
zimport not able to import a module from zipfile if zipfile contains
comment.
Versions:
This is Zip 2.32 (June 19th 2006), by Info-ZIP
Python 2.5.2 or 2.6.2

Steps to reproduce:
create a module, create an app that imports this module.
zip the module, make sure it works. 
Run: echo "Some comments" | zip -z module.zip
the app stop working.
msg97316 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2010-01-06 18:26
Yes, comments are not supported right now. Documented this in r77333, and turning this issue into a feature request for adding that support.
msg109678 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2010-07-09 04:30
Does 'zimport' refer to the 3.1 zipfile or zipimport modules or an internal function called zimport?
msg109686 - (view) Author: Dmitry (dsamersoff) Date: 2010-07-09 07:00
I'm talking about internal zimport function (see attached testcase): 

i.e.

import sys;
sys.path.insert(0,'test.zip');

import test
test.testme()

doesn't work if test.zip contains comment.
msg110014 - (view) Author: Ryan Kelly (rfk) Date: 2010-07-11 14:24
Attached is my attempt at a patch for this functionality, along with some simple tests.  This basically mirrors what's done in zipfile.py, searching backwards through the file until it finds the end-of-central-directory marker.  It tries to be memory conscious by reading in small chunks.

Patch is against trunk; I've also tested it against 2.7 and it seems to work.  Any chance of it being backported into 2.7?

Also wanted to mention a real-world usecase for this functionality. I want to digitally sign a frozen python program with appended zipfile, which involves appending the signature to the EXE.  Simple to do if only zipimport would support appended comments.
msg110016 - (view) Author: Ryan Kelly (rfk) Date: 2010-07-11 14:26
Whoops, forgot to remove the line from the docs about comments not being supported.  Updated the patch accordingly.
msg110059 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2010-07-12 00:17
"the line from the docs about comments not being supported." answers your question. Current behavior is documented behavior and therefor changing it is not a bugfix.
msg110151 - (view) Author: Ryan Kelly (rfk) Date: 2010-07-13 00:26
I can't imagine anyone depending on this lack-of-feature, but there's no arguing with the technicality of it.  One more small incentive to make the jump to Python 3 then.

Anyway, I've revisited the patch to clean up the logic and control flow, and added another test to ensure that it works even when the EOCD record crosses a chunk boundary.  Also checked that it works on win32, which fortunately it did without modification.
msg110157 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2010-07-13 04:53
>I can't imagine anyone depending on this lack-of-feature,

Neither can I, but I can imaging someone writing code that depended on the feature. If added to 3.1.3, then code that depended on it would not run on 3.1, 3.1.1, and 3.1.2. The same is true, of course, for bug fixes, but the doc does not need changing for bug fixes, and the impact is otherwise less.

> One more small incentive to make the jump to Python 3 then.

Or to 3.2 from any 3.1 version, which is the normal progession absent the dual track anomaly.
msg113452 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2010-08-09 18:54
I believe this is covered by the PEP3003 3.2 change moratorium.
msg113467 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2010-08-09 20:33
Why?
msg113484 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2010-08-09 21:59
Because it adds a feature to the import statement, rather than to a module, or so Dmitry said. But fine with me if it goes in now.
msg113486 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2010-08-09 22:02
On #1644818, Brett said import statement is exempt from moratorium.
msg139187 - (view) Author: engelbert gruber (grubert) * Date: 2011-06-26 15:11
+1*4
msg139192 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2011-06-26 17:19
Brett, Nick, this could be considered a patch to the import machinery as the bugs shows with a import statement. In any case, no one is signed up for zipimport specifically.
msg175127 - (view) Author: Dima Tisnek (Dima.Tisnek) Date: 2012-11-07 22:13
also applies to 2.7 series

over a year passed since last comment, any progress on this?

I just ran into this issue myself.
zipfile module handles commented zip's fine, but zipimport doesn't.
I didn't expect a gotcha like this from Python!
msg175169 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2012-11-08 14:46
This is a feature request so it won't change in Python 2.7.

As for progress, the answer is no as the hope is to eventually replace zipimport with something in pure Python thanks to importlib.
msg219263 - (view) Author: Thomas Heller (theller) * (Python committer) Date: 2014-05-28 11:26
> As for progress, the answer is no as the hope is to eventually replace
> zipimport with something in pure Python thanks to importlib.

Does this mean there is no chance to put this into 3.4 and 3.3, do we really have to wait until 3.5 with it's pure-python zipimport?

I (together with the py2exe-users) have the same usecase as Ryan Kelly in msg110014:

> I want to digitally sign a frozen python program with appended zipfile,
> which involves appending the signature to the EXE.  Simple to do if
> only zipimport would support appended comments.
msg219266 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2014-05-28 13:25
I actually stopped development of a pure Python zip importer so it won't be in Python 3.5 either (http://bugs.python.org/issue17630). The motivation simply wasn't there if zipimport is going to be sticking around for bootstrapping reasons. This can still get fixed in 3.5 (3.4 is Larry's call).

I have added Thomas Wouters and Greg Smith who have done the most work with zipimport to the nosy list to see if they have interest in taking a look at the patch.
msg226234 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-09-01 16:36
See issue22322 for yet one use case ("git archive" creates ZIP file with archive comment).
History
Date User Action Args
2014-09-01 16:36:16serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg226234
2014-09-01 16:26:14r.david.murraylinkissue22322 superseder
2014-05-28 13:53:50peter.ottensetnosy: + peter.otten
2014-05-28 13:25:40brett.cannonsetnosy: + twouters, gregory.p.smith
messages: + msg219266
2014-05-28 11:27:01thellersetnosy: + theller
messages: + msg219263
2012-11-13 02:53:40eric.snowsetnosy: + eric.snow
2012-11-08 14:46:22brett.cannonsetmessages: + msg175169
versions: + Python 3.4, - Python 2.7, Python 3.3
2012-11-07 22:13:10Dima.Tisneksetnosy: + Dima.Tisnek

messages: + msg175127
versions: + Python 2.7
2011-06-26 17:19:39terry.reedysetnosy: + brett.cannon, ncoghlan

messages: + msg139192
versions: + Python 3.3, - Python 3.2
2011-06-26 15:11:51grubertsetnosy: + grubert
messages: + msg139187
2010-08-09 22:02:33terry.reedysetmessages: + msg113486
2010-08-09 21:59:48terry.reedysetmessages: + msg113484
stage: patch review
2010-08-09 20:33:27georg.brandlsetmessages: + msg113467
versions: + Python 3.2, - Python 3.3
2010-08-09 18:54:07terry.reedysetmessages: + msg113452
versions: + Python 3.3, - Python 3.2
2010-07-13 04:53:21terry.reedysetmessages: + msg110157
2010-07-13 00:28:24rfksetfiles: - zipimport_with_comments.patch
2010-07-13 00:26:13rfksetfiles: + zipimport_with_comments.patch

messages: + msg110151
2010-07-12 00:17:01terry.reedysetmessages: + msg110059
2010-07-11 15:37:03georg.brandlsettitle: Make zimport work with zipfile containing comments -> Make zipimport work with zipfile containing comments
2010-07-11 14:26:26rfksetfiles: - zipimport_with_comments.patch
2010-07-11 14:26:14rfksetfiles: + zipimport_with_comments.patch

messages: + msg110016
2010-07-11 14:24:04rfksetfiles: + zipimport_with_comments.patch
keywords: + patch
messages: + msg110014
2010-07-11 13:31:57rfksetnosy: + rfk
2010-07-09 07:00:31dsamersoffsetmessages: + msg109686
2010-07-09 04:30:26terry.reedysetnosy: + terry.reedy
title: zimport doesn't work with zipfile containing comments -> Make zimport work with zipfile containing comments
messages: + msg109678

versions: + Python 3.2, - Python 2.6, Python 2.5
2010-01-06 18:26:34georg.brandlsettype: enhancement

messages: + msg97316
nosy: + georg.brandl
2009-05-06 16:49:46dsamersoffcreate