summaryrefslogtreecommitdiffstats
path: root/Lib/tarfile.py
diff options
context:
space:
mode:
authorPetr Viktorin <encukou@gmail.com>2023-08-21 10:56:46 (GMT)
committerGitHub <noreply@github.com>2023-08-21 10:56:46 (GMT)
commitacbd3f9c5c5f23e95267714e41236140d84fe962 (patch)
tree0372b9168b6554b0591152c3a2583638a8e84cda /Lib/tarfile.py
parent622ddc41674c2566062af82f7b079aa01d2aae8c (diff)
downloadcpython-acbd3f9c5c5f23e95267714e41236140d84fe962.zip
cpython-acbd3f9c5c5f23e95267714e41236140d84fe962.tar.gz
cpython-acbd3f9c5c5f23e95267714e41236140d84fe962.tar.bz2
gh-107845: Fix symlink handling for tarfile.data_filter (GH-107846)
Co-authored-by: Victor Stinner <vstinner@python.org> Co-authored-by: Lumír 'Frenzy' Balhar <frenzy.madness@gmail.com>
Diffstat (limited to 'Lib/tarfile.py')
-rwxr-xr-xLib/tarfile.py11
1 files changed, 9 insertions, 2 deletions
diff --git a/Lib/tarfile.py b/Lib/tarfile.py
index df4e41f..1147d59 100755
--- a/Lib/tarfile.py
+++ b/Lib/tarfile.py
@@ -742,7 +742,7 @@ class SpecialFileError(FilterError):
class AbsoluteLinkError(FilterError):
def __init__(self, tarinfo):
self.tarinfo = tarinfo
- super().__init__(f'{tarinfo.name!r} is a symlink to an absolute path')
+ super().__init__(f'{tarinfo.name!r} is a link to an absolute path')
class LinkOutsideDestinationError(FilterError):
def __init__(self, tarinfo, path):
@@ -802,7 +802,14 @@ def _get_filtered_attrs(member, dest_path, for_data=True):
if member.islnk() or member.issym():
if os.path.isabs(member.linkname):
raise AbsoluteLinkError(member)
- target_path = os.path.realpath(os.path.join(dest_path, member.linkname))
+ if member.issym():
+ target_path = os.path.join(dest_path,
+ os.path.dirname(name),
+ member.linkname)
+ else:
+ target_path = os.path.join(dest_path,
+ member.linkname)
+ target_path = os.path.realpath(target_path)
if os.path.commonpath([target_path, dest_path]) != dest_path:
raise LinkOutsideDestinationError(member, target_path)
return new_attrs