Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9f478c0

Browse files
committed
Merge with 3.2: Issue #14160: TarFile.extractfile() failed to resolve symbolic
links when the links were not located in an archive subdirectory.
2 parents 1d642d2 + 1ef9eda commit 9f478c0

4 files changed

Lines changed: 7 additions & 1 deletion

File tree

Lib/tarfile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2481,7 +2481,7 @@ def _find_link_target(self, tarinfo):
24812481
"""
24822482
if tarinfo.issym():
24832483
# Always search the entire archive.
2484-
linkname = os.path.dirname(tarinfo.name) + "/" + tarinfo.linkname
2484+
linkname = "/".join(filter(None, (os.path.dirname(tarinfo.name), tarinfo.linkname)))
24852485
limit = None
24862486
else:
24872487
# Search the archive before the link, because a hard link is

Lib/test/test_tarfile.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,9 @@ def test_fileobj_symlink1(self):
171171
def test_fileobj_symlink2(self):
172172
self._test_fileobj_link("./ustar/linktest2/symtype", "ustar/linktest1/regtype")
173173

174+
def test_issue14160(self):
175+
self._test_fileobj_link("symtype2", "ustar/regtype")
176+
174177

175178
class CommonReadTest(ReadTest):
176179

Lib/test/testtar.tar

8 KB
Binary file not shown.

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ Core and Builtins
7171
Library
7272
-------
7373

74+
- Issue #14160: TarFile.extractfile() failed to resolve symbolic links when
75+
the links were not located in an archive subdirectory.
76+
7477
- Issue #14638: pydoc now treats non-string __name__ values as if they
7578
were missing, instead of raising an error.
7679

0 commit comments

Comments
 (0)