tarfilter: do not rely on paths being absolute (starting with a single slash)

This commit is contained in:
Johannes Schauer Marin Rodrigues 2024-09-13 01:16:31 +02:00
parent acf036fa79
commit 87b9b385b3
Signed by: josch
GPG key ID: F2CBA5C78FBD83E1

View file

@ -218,8 +218,11 @@ Lastly, shift user id and group id of each entry by the value given by the
skip = False
if not hasattr(args, "pathfilter"):
return False
# normalize path and make it absolute by stripping off all leading
# dots and slashes and then prepending a slash
name = "/" + member.name.lstrip("./")
for t, r in args.pathfilter:
if r.match(member.name[1:]) is not None:
if r.match(name) is not None:
if t == "path_include":
skip = False
else:
@ -230,7 +233,7 @@ Lastly, shift user id and group id of each entry by the value given by the
continue
prefix = prefix_prog.sub(r"\1", r.pattern)
prefix = prefix.rstrip("/")
if member.name[1:].startswith(prefix):
if name.startswith(prefix):
return False
return skip