From: Philipp Gesang Date: Thu, 3 Nov 2016 13:31:14 +0000 (+0100) Subject: delay only absolute symlinks and those pointing to parent dirs X-Git-Tag: v2.2~8^2~7 X-Git-Url: http://developer.intra2net.com/git/?a=commitdiff_plain;h=dfb00a257e35d61c74fa0e8ad86ef4e6a4429c74;p=python-delta-tar delay only absolute symlinks and those pointing to parent dirs Only apply the symlink hook on those with fishy targets. Internal symlinks need not be contained so they can be applied as-is. --- diff --git a/deltatar/tarfile.py b/deltatar/tarfile.py index 713423c..78da665 100644 --- a/deltatar/tarfile.py +++ b/deltatar/tarfile.py @@ -275,6 +275,28 @@ def filemode(mode): DeprecationWarning, 2) return stat.filemode(mode) +def contains_dot_dot(name): + """Check whether a path contains double dots thus referring to the parent + directory. + """ + l = len(name) + if l < 2: + return False + p = 0 + while True: + if name[p] == '.' and name[p + 1] == '.': + ppp = p + 2 + if ppp == l or name[ppp] == '/': + return True + while name[p] != '/': + if p == l - 2: + return False + p += 1 + if p == l - 2: + break + p += 1 + return False + class TarError(Exception): """Base exception.""" pass @@ -2659,7 +2681,9 @@ class TarFile(object): if tarinfo.islnk(): tarinfo._link_target = os.path.join(path, tarinfo.linkname) - if symlink_cb is not None and tarinfo.issym(): + if symlink_cb is not None and tarinfo.issym() \ + and (os.path.isabs(tarinfo.linkname) + or contains_dot_dot(tarinfo.linkname)): return symlink_cb(tarinfo, path, set_attrs) try: