]> granicus.if.org Git - python/commitdiff
Merged revisions 81663 via svnmerge from
authorLars Gustäbel <lars@gustaebel.de>
Thu, 3 Jun 2010 10:11:52 +0000 (10:11 +0000)
committerLars Gustäbel <lars@gustaebel.de>
Thu, 3 Jun 2010 10:11:52 +0000 (10:11 +0000)
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r81663 | lars.gustaebel | 2010-06-03 11:56:22 +0200 (Thu, 03 Jun 2010) | 4 lines

  Issue #8833: tarfile created hard link entries with a size
  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 e9480c82d5e55346c14e7a62b7b58d29a1ac4bee..8559e96fada60a45e8729e4dce4674b312b94193 100644 (file)
@@ -1920,7 +1920,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 = 0
index c0741ee5e5fbee6c72d8a29a8ad340852f272525..ec6f82fd8bfcb33005726bdc051302455e223aa9 100644 (file)
@@ -661,10 +661,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(b"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 4c60de3f22329c649bf15494df66e3a371160389..9195a04152df5a852aeade58b74982fa64a881e7 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -398,6 +398,9 @@ C-API
 Library
 -------
 
+- Issue #8833: tarfile created hard link entries with a size field != 0 by
+  mistake.
+
 - Charset.body_encode now correctly handles base64 encoding by encoding
   with the output_charset before calling base64mime.encode.  Passes the
   tests from 2.x issue 1368247.