[issue3394] zipfile.writestr doesn't set external attributes, so files are extracted mode 000 on Unix

2008-07-25 Thread Antoine Pitrou

Antoine Pitrou [EMAIL PROTECTED] added the comment:

Agree with using 0600 as default permissions.

--
nosy: +pitrou
priority:  - high

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue3394
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue3394] zipfile.writestr doesn't set external attributes, so files are extracted mode 000 on Unix

2008-07-25 Thread Mark Summerfield

Changes by Mark Summerfield [EMAIL PROTECTED]:


--
nosy: +mark

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue3394
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue3394] zipfile.writestr doesn't set external attributes, so files are extracted mode 000 on Unix

2008-07-25 Thread Antoine Pitrou

Antoine Pitrou [EMAIL PROTECTED] added the comment:

Committed in r65235. Thanks!

--
resolution:  - fixed
status: open - closed

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue3394
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue3394] zipfile.writestr doesn't set external attributes, so files are extracted mode 000 on Unix

2008-07-24 Thread Dylan Grose

Changes by Dylan Grose [EMAIL PROTECTED]:


--
nosy: +dkbg

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue3394
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue3394] zipfile.writestr doesn't set external attributes, so files are extracted mode 000 on Unix

2008-07-18 Thread Christopher Brannon

Christopher Brannon [EMAIL PROTECTED] added the comment:

Here is a patch containing code and a unit test.  I set external_attr
to 0600, for the following reason.
When I extract with Infozip, my umask is ignored when setting permissions of
extracted entries.  They have the permissions assigned to them when archived.
tar does respect umask, but it's not pertinent.
The following shell script demonstrates Infozip's behavior:

=begin=
#!/bin/sh
mkdir ziptest_dir
echo hello  ziptest_dir/foo.txt
chmod 666 ziptest_dir/foo.txt
zip -r ziptest_file.zip ziptest_dir/
rm -rf ziptest_dir
umask 077
unzip ziptest_file.zip
=end=

Setting permissions to 0600 seems like the safest course.

I'm not sure if this patch should be accompanied by some documentation,
since the zipfile docs don't say much about external_attr or permissions.

PS.  My earlier comments about timestamps were incorrect and spurious!

--
keywords: +patch
Added file: http://bugs.python.org/file10933/writestr_usable_permissions.diff

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue3394
___Index: Lib/zipfile.py
===
--- Lib/zipfile.py  (revision 65056)
+++ Lib/zipfile.py  (working copy)
@@ -2,7 +2,7 @@
 Read and write ZIP files.
 
 import struct, os, time, sys, shutil
-import binascii, cStringIO
+import binascii, cStringIO, stat
 
 try:
 import zlib # We may need its compression method
@@ -1064,6 +1064,8 @@
 zinfo = ZipInfo(filename=zinfo_or_arcname,
 date_time=time.localtime(time.time())[:6])
 zinfo.compress_type = self.compression
+# zinfo.external_attr = 0600  16
+zinfo.external_attr = (stat.S_IRUSR | stat.S_IWUSR)  16
 else:
 zinfo = zinfo_or_arcname
 
Index: Lib/test/test_zipfile.py
===
--- Lib/test/test_zipfile.py(revision 65056)
+++ Lib/test/test_zipfile.py(working copy)
@@ -372,6 +372,20 @@
 # remove the test file subdirectories
 shutil.rmtree(os.path.join(os.getcwd(), 'ziptest2dir'))
 
+def zip_test_writestr_permissions(self, f, compression):
+# Make sure that writestr creates files with mode 0600,
+# when it is passed a name rather than a ZipInfo instance.
+
+self.makeTestArchive(f, compression)
+zipfp = zipfile.ZipFile(f, r)
+zinfo = zipfp.getinfo('strfile')
+self.assertEqual(zinfo.external_attr, 0600  16)
+
+def test_writestr_permissions(self):
+for f in (TESTFN2, TemporaryFile(), StringIO()):
+self.zip_test_writestr_permissions(f, zipfile.ZIP_STORED)
+
+
 def tearDown(self):
 os.remove(TESTFN)
 os.remove(TESTFN2)
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue3394] zipfile.writestr doesn't set external attributes, so files are extracted mode 000 on Unix

2008-07-17 Thread Stephen Warren

New submission from Stephen Warren [EMAIL PROTECTED]:

Run the following Python script, on Unix/Linux:

==
import zipfile

z = zipfile.ZipFile('zipbad.zip', 'w')
z.writestr('filebad.txt', 'Some content')
z.close()

z = zipfile.ZipFile('zipgood.zip', 'w')
zi = zipfile.ZipInfo('filegood.txt')
zi.external_attr = 0660  16L
z.writestr(zi, 'Some content')
z.close()
==

Like this:

python testzip.py   unzip zipbad.zip  unzip zipgood.zip  ls -l
file*.txt

You'll see:

--  1 swarren swarren   12 2008-07-17 12:54 filebad.txt
-rw-rw  1 swarren swarren   12 1980-01-01 00:00 filegood.txt

Note that filebad.txt is extracted with mode 000.

The WAR (used for filegood.txt) is to pass writestr a ZipInfo class with
external_attr pre-initialized. However, writestr should perform this
assignment itself, to be consistent with write. I haven't checked, but
there's probably a bunch of other stuff in write that writestr should do
too.

--
components: Extension Modules
messages: 69898
nosy: swarren
severity: normal
status: open
title: zipfile.writestr doesn't set external attributes, so files are extracted 
mode 000 on Unix
versions: Python 2.5

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue3394
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue3394] zipfile.writestr doesn't set external attributes, so files are extracted mode 000 on Unix

2008-07-17 Thread Stephen Warren

Stephen Warren [EMAIL PROTECTED] added the comment:

Oops. Forgot to set type field.

--
type:  - behavior

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue3394
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue3394] zipfile.writestr doesn't set external attributes, so files are extracted mode 000 on Unix

2008-07-17 Thread Christopher Brannon

Christopher Brannon [EMAIL PROTECTED] added the comment:

What value should the new archive entry's external_attr attribute have?
ZipFile.write sets it to the permissions of the file being archived, but
writestr is archiving a string, not a file.  Setting it to 0600 lt;lt; 16
seems reasonable.

Stephen's script exposed a second bug in writestr.  When passed a name
rather than a ZipInfo instance, the new archive member receives a timestamp
of 01/01/1980.  However, the docs say that the timestamp should correspond to
the current date and time.
ZipFile.writestr begins with the following code:

def writestr(self, zinfo_or_arcname, bytes):
Write a file into the archive.  The contents is the string
'bytes'.  'zinfo_or_arcname' is either a ZipInfo instance or
the name of the file in the archive.
if not isinstance(zinfo_or_arcname, ZipInfo):
zinfo = ZipInfo(filename=zinfo_or_arcname,
date_time=time.localtime(time.time())[:6])
zinfo.compress_type = self.compression

The date_time= line should read:

zinfo.date_time=time.localtime(time.time())[:6])

--
nosy: +cbrannon
versions: +Python 2.6

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue3394
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue3394] zipfile.writestr doesn't set external attributes, so files are extracted mode 000 on Unix

2008-07-17 Thread Stephen Warren

Stephen Warren [EMAIL PROTECTED] added the comment:

I'd probably argue for at least 066016, if not 066616, since group
permissions are pretty typically set, but even 066616 would be OK,
since the umask on extraction would take away any permissions the
extracting user didn't want.

But, as long as the chosen mask includes at least 0600, I'd consider the
issue fixed.

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue3394
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com