L

py7zlib patch

Feb. 6th 2009 02:43:34

-0

If you go to the py7zlib page you will see a comment describing a problem with the timestamps. I was having a similar problem with the timestamps, except the comment didn't provide a patch or a way to convert time time. This problem exists in svn trunk as of this writing, although it was discovered a year ago. The issue is perhaps due to a slight fileformat shift, but essentially there is an extra byte (or 9) that are not being read and shifting the time results.

As a note to myself (and others, and joachim bauch), I've added the missing patch and a quick in-code explanation of the time situation in 7zip archives. Note that you can see a very detailed and helpful textfile called "7zFormat.txt" in the p7zip sources. 7zip stores its time the same way winnt stores its time; in 100's of nanoseconds since an epoch of midnight January 01, 1601. As it turns out this is 11644473600 seconds before the unix epoch; add 7 0's and you have nanoseconds:

    import time
    tconvert = lambda t: time.gmtime((t - 116444736000000000L) / 10000000.0)

A patch for pylzma is available and reproduced below (note the last line is a bit off; issues w/ pygment's diff/udiff/python lexers):

Index: py7zlib.py
===================================================================
--- py7zlib.py  (revision 132)
+++ py7zlib.py  (working copy)
@@ -30,6 +30,7 @@
 from zlib import crc32
 from cStringIO import StringIO
+VERSION                          = "0.3.1-jm"
 MAGIC_7Z                         = '7z\xbc\xaf\x27\x1c'
PROPERTY_END                     = '\x00'
@@ -321,7 +322,10 @@
     def _readTimes(self, file, files, name):
         defined = self._readBoolean(file, len(files), checkall=1)
-        
+        # read the external byte
+        external = ord(file.read(1))
+        if external:
+            dataindex = self._readReal64Bit(file)
         for i in xrange(len(files)):
             if defined[i]:
                 files[i][name] = self._readReal64Bit(file)[0] #unpack('L', file.read(4))[0]

comments

+ leave a comment on "py7zlib patch"