]> granicus.if.org Git - python/commitdiff
Issue #8833: tarfile created hard link entries with a size
authorLars Gustäbel <lars@gustaebel.de>
Thu, 3 Jun 2010 09:56:22 +0000 (09:56 +0000)
committerLars Gustäbel <lars@gustaebel.de>
Thu, 3 Jun 2010 09:56:22 +0000 (09:56 +0000)
field != 0 by mistake. The associated testcase did not
expose this bug because it was broken too.

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

index 4b03c28305841defb6d5e9ea4323392750a923ef..a54b3b88ad6f7557bed6e0312a6fa426c00c9423 100644 (file)
@@ -1884,7 +1884,7 @@ class TarFile(object):
         tarinfo.mode = stmd
         tarinfo.uid = statres.st_uid
         tarinfo.gid = statres.st_gid
-        if stat.S_ISREG(stmd):
+        if type == REGTYPE:
             tarinfo.size = statres.st_size
         else:
             tarinfo.size = 0L
index 52d6ab3a88977af39020733adaff8315b4b59ccd..0d58cdacfffc4c9ae03045cd3c3ef8de580a073e 100644 (file)
@@ -662,10 +662,14 @@ class WriteTest(WriteTestBase):
         if hasattr(os, "link"):
             link = os.path.join(TEMPDIR, "link")
             target = os.path.join(TEMPDIR, "link_target")
-            open(target, "wb").close()
+            fobj = open(target, "wb")
+            fobj.write("aaa")
+            fobj.close()
             os.link(target, link)
             try:
                 tar = tarfile.open(tmpname, self.mode)
+                # Record the link target in the inodes list.
+                tar.gettarinfo(target)
                 tarinfo = tar.gettarinfo(link)
                 self.assertEqual(tarinfo.size, 0)
             finally:
index cd9da3773bfaa21fd690ca14ffa471edcdb39966..9debe2cdc20b546d3579f8634728967a2a59763f 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -46,6 +46,9 @@ C-API
 Library
 -------
 
+- Issue #8833: tarfile created hard link entries with a size field != 0 by
+  mistake.
+
 - Issue #1368247: set_charset (and therefore MIMEText) now automatically
   encodes a unicode _payload to the output_charset.