From 1ef9eda7bcddc494a250a6fb262c0dd3327dc443 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Lars=20Gust=C3=A4bel?= Date: Tue, 24 Apr 2012 21:04:40 +0200 Subject: [PATCH] Issue #14160: TarFile.extractfile() failed to resolve symbolic links when the links were not located in an archive subdirectory. --- Lib/tarfile.py | 2 +- Lib/test/test_tarfile.py | 3 +++ Lib/test/testtar.tar | Bin 427008 -> 435200 bytes Misc/NEWS | 3 +++ 4 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Lib/tarfile.py b/Lib/tarfile.py index af32b0f2cb..f26953e2bb 100644 --- a/Lib/tarfile.py +++ b/Lib/tarfile.py @@ -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 diff --git a/Lib/test/test_tarfile.py b/Lib/test/test_tarfile.py index 1757e4495b..f32eb8c438 100644 --- a/Lib/test/test_tarfile.py +++ b/Lib/test/test_tarfile.py @@ -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): diff --git a/Lib/test/testtar.tar b/Lib/test/testtar.tar index b93210453d132cf0db07ab26cb50d06f83ee579a..bb9345373e9701b01f16b70844445dfe1863abc6 100644 GIT binary patch delta 148 zcmZqZkZL#~)v$!|7e{erZb@Z9s?p>^*_dg1Oe~W#ob=gD4Gb6*j3&vYOp;@r%*Obu z?H6O)FQ#R`n9oeRz{J8|l$s9Gqnn;rs#}_wGEp!Pq*KJq#Dt-Nfq~&a5Wwi^HFFrH p*bEKK%^4J?D=M)#PgGC>8oC*1sLV7bR^fKxV=UW+kFmbp3jmG#G`j!* delta 27 jcmZoTA=S_!)v$!|SKA-Pwm(eE{xF|ud&aWt8S6d(yLJuR diff --git a/Misc/NEWS b/Misc/NEWS index 2d58cb618e..08254d4dda 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. -- 2.40.0