From: Neal Norwitz Date: Mon, 21 Aug 2006 17:59:46 +0000 (+0000) Subject: Fix bug #1543303, tarfile adds padding that breaks gunzip. X-Git-Tag: v2.6a1~2763 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8a519392d5be32adf77ceab86f7f637a7e0835f5;p=python Fix bug #1543303, tarfile adds padding that breaks gunzip. Patch # 1543897. Will backport to 2.5 --- diff --git a/Lib/tarfile.py b/Lib/tarfile.py index c185fbd49e..38cccae1d5 100644 --- a/Lib/tarfile.py +++ b/Lib/tarfile.py @@ -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": diff --git a/Lib/test/test_tarfile.py b/Lib/test/test_tarfile.py index 8ee0f41ea8..ebcb8c59f5 100644 --- a/Lib/test/test_tarfile.py +++ b/Lib/test/test_tarfile.py @@ -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.