]> granicus.if.org Git - python/commitdiff
Issue #14160: TarFile.extractfile() failed to resolve symbolic links when
authorLars Gustäbel <lars@gustaebel.de>
Tue, 24 Apr 2012 20:42:08 +0000 (22:42 +0200)
committerLars Gustäbel <lars@gustaebel.de>
Tue, 24 Apr 2012 20:42:08 +0000 (22:42 +0200)
the links were not located in an archive subdirectory.

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

index bd73965abf85d7f02fa371839a0a87ecfdd91091..02858ae035a19845cf64d193cb26acaaa8e7bff4 100644 (file)
@@ -2397,7 +2397,7 @@ class TarFile(object):
         """
         if tarinfo.issym():
             # Always search the entire archive.
-            linkname = os.path.dirname(tarinfo.name) + "/" + tarinfo.linkname
+            linkname = "/".join(filter(None, (os.path.dirname(tarinfo.name), tarinfo.linkname)))
             limit = None
         else:
             # Search the archive before the link, because a hard link is
index d5b864e238b41c1ceeb82de6356612fb08d44a96..a3685ea273a46fb9507ae6c0dd20205b2fef8d86 100644 (file)
@@ -154,6 +154,9 @@ class UstarReadTest(ReadTest):
     def test_fileobj_symlink2(self):
         self._test_fileobj_link("./ustar/linktest2/symtype", "ustar/linktest1/regtype")
 
+    def test_issue14160(self):
+        self._test_fileobj_link("symtype2", "ustar/regtype")
+
 
 class CommonReadTest(ReadTest):
 
index bac0e2628f35243f236db2fac82737882699b2f0..440182a437da84ef3d61d8cbc0f4209254615b37 100644 (file)
Binary files a/Lib/test/testtar.tar and b/Lib/test/testtar.tar differ
index 282a8eb265daa40681154056882bce791a4c1cd6..1e088c03e0593545cd88543800778cb11f568279 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -56,6 +56,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #14160: TarFile.extractfile() failed to resolve symbolic links when
+  the links were not located in an archive subdirectory.
+
 - Issue #14638: pydoc now treats non-string __name__ values as if they
   were missing, instead of raising an error.