[Python-checkins] r51432 - in python/trunk/Lib: tarfile.py test/test_tarfile.py

neal.norwitz python-checkins at python.org
Mon Aug 21 19:59:47 CEST 2006


Author: neal.norwitz
Date: Mon Aug 21 19:59:46 2006
New Revision: 51432

Modified:
   python/trunk/Lib/tarfile.py
   python/trunk/Lib/test/test_tarfile.py
Log:
Fix bug #1543303, tarfile adds padding that breaks gunzip.
Patch # 1543897.

Will backport to 2.5


Modified: python/trunk/Lib/tarfile.py
==============================================================================
--- python/trunk/Lib/tarfile.py	(original)
+++ python/trunk/Lib/tarfile.py	Mon Aug 21 19:59:46 2006
@@ -411,9 +411,6 @@
             self.buf += self.cmp.flush()
 
         if self.mode == "w" and self.buf:
-            blocks, remainder = divmod(len(self.buf), self.bufsize)
-            if remainder > 0:
-                self.buf += NUL * (self.bufsize - remainder)
             self.fileobj.write(self.buf)
             self.buf = ""
             if self.comptype == "gz":

Modified: python/trunk/Lib/test/test_tarfile.py
==============================================================================
--- python/trunk/Lib/test/test_tarfile.py	(original)
+++ python/trunk/Lib/test/test_tarfile.py	Mon Aug 21 19:59:46 2006
@@ -324,6 +324,27 @@
 class WriteStreamTest(WriteTest):
     sep = '|'
 
+    def test_padding(self):
+        self.dst.close()
+
+        if self.comp == "gz":
+            f = gzip.GzipFile(self.dstname)
+            s = f.read()
+            f.close()
+        elif self.comp == "bz2":
+            f = bz2.BZ2Decompressor()
+            s = file(self.dstname).read()
+            s = f.decompress(s)
+            self.assertEqual(len(f.unused_data), 0, "trailing data")
+        else:
+            f = file(self.dstname)
+            s = f.read()
+            f.close()
+
+        self.assertEqual(s.count("\0"), tarfile.RECORDSIZE,
+                         "incorrect zero padding")
+
+
 class WriteGNULongTest(unittest.TestCase):
     """This testcase checks for correct creation of GNU Longname
        and Longlink extensions.


More information about the Python-checkins mailing list