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

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

index af32b0f2cbd9d3d65345bc7d0f97460768400718..f26953e2bb1f69ddeb91575ceedc23685f6ebf77 100644 (file)
@@ -2496,7 +2496,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 1757e4495b10ea0efe55b76a46de87bbc6d9b1ad..f32eb8c438d63d6f452b67e2b4b22041ec8138b5 100644 (file)
@@ -166,6 +166,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 b93210453d132cf0db07ab26cb50d06f83ee579a..bb9345373e9701b01f16b70844445dfe1863abc6 100644 (file)
Binary files a/Lib/test/testtar.tar and b/Lib/test/testtar.tar differ
index 2d58cb618e6cd14446fa457cee62721b3c2678d3..08254d4dda3367e899dbe435a1407d1f225509f9 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.