From 87b9b385b38795c58bc13ffb33b8724bed27f7a0 Mon Sep 17 00:00:00 2001 From: Johannes Schauer Marin Rodrigues Date: Fri, 13 Sep 2024 01:16:31 +0200 Subject: [PATCH] tarfilter: do not rely on paths being absolute (starting with a single slash) --- tarfilter | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tarfilter b/tarfilter index 66ef229..ad77616 100755 --- a/tarfilter +++ b/tarfilter @@ -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