]> granicus.if.org Git - python/commitdiff
Backport 51432:
authorNeal Norwitz <nnorwitz@gmail.com>
Mon, 21 Aug 2006 18:43:51 +0000 (18:43 +0000)
committerNeal Norwitz <nnorwitz@gmail.com>
Mon, 21 Aug 2006 18:43:51 +0000 (18:43 +0000)
Fix bug #1543303, tarfile adds padding that breaks gunzip.
Patch # 1543897.  (remove the padding)

Lib/tarfile.py
Lib/test/test_tarfile.py
Misc/NEWS

index c185fbd49eb0bc577c58fa46f60bd2d6f4652843..38cccae1d5ee06fd708cea681ff4c8d2092d5501 100644 (file)
@@ -411,9 +411,6 @@ class _Stream:
             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":
index 8ee0f41ea8b8b9e474de52b0941d8ba04784877a..ebcb8c59f5dc9c07ef9d075049815af4f69de0ed 100644 (file)
@@ -324,6 +324,27 @@ class WriteSize0Test(BaseTest):
 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.
index 537c4b1508d33cdb24d1d02668fde3596925bbe2..edeff46effea297b40de5bb1798dce1df068349f 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -15,6 +15,8 @@ Library
 - Bug #1541863: uuid.uuid1 failed to generate unique identifiers
   on systems with low clock resolution.
 
+- Bug #1543303, patch #1543897: remove NUL padding from tarfiles.
+
 
 Documentation
 -------------