diff --git a/Lib/tarfile.py b/Lib/tarfile.py index af32b0f2cbd..f26953e2bb1 100644 --- a/Lib/tarfile.py +++ b/Lib/tarfile.py @@ -2496,7 +2496,7 @@ def _find_link_target(self, tarinfo): """ 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 1757e4495b1..f32eb8c438d 100644 --- a/Lib/test/test_tarfile.py +++ b/Lib/test/test_tarfile.py @@ -166,6 +166,9 @@ def test_fileobj_symlink1(self): 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 b93210453d1..bb9345373e9 100644 Binary files a/Lib/test/testtar.tar and b/Lib/test/testtar.tar differ diff --git a/Misc/NEWS b/Misc/NEWS index 2d58cb618e6..08254d4dda3 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.