summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Gustäbel <lars@gustaebel.de>2012-04-24 22:42:08 +0200
committerLars Gustäbel <lars@gustaebel.de>2012-04-24 22:42:08 +0200
commit231d474a7b1747d22c383802473fb15b549f22cb (patch)
treed8f44fb9c4b3b0f9db2e704010ce9e641a57f619
parent13c598b1d862b7f7f7359671e3944e81882b19b1 (diff)
downloadcpython-git-231d474a7b1747d22c383802473fb15b549f22cb.tar.gz
Issue #14160: TarFile.extractfile() failed to resolve symbolic links when
the links were not located in an archive subdirectory.
-rw-r--r--Lib/tarfile.py2
-rw-r--r--Lib/test/test_tarfile.py3
-rw-r--r--Lib/test/testtar.tarbin281088 -> 281600 bytes
-rw-r--r--Misc/NEWS3
4 files changed, 7 insertions, 1 deletions
diff --git a/Lib/tarfile.py b/Lib/tarfile.py
index bd73965abf..02858ae035 100644
--- a/Lib/tarfile.py
+++ b/Lib/tarfile.py
@@ -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
diff --git a/Lib/test/test_tarfile.py b/Lib/test/test_tarfile.py
index d5b864e238..a3685ea273 100644
--- a/Lib/test/test_tarfile.py
+++ b/Lib/test/test_tarfile.py
@@ -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):
diff --git a/Lib/test/testtar.tar b/Lib/test/testtar.tar
index bac0e2628f..440182a437 100644
--- a/Lib/test/testtar.tar
+++ b/Lib/test/testtar.tar
Binary files differ
diff --git a/Misc/NEWS b/Misc/NEWS
index 282a8eb265..1e088c03e0 100644
--- 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.