Skip to content

Commit 4d65832

Browse files
fix(tar) properly extract relative symlinks
symlinks like sbin/halt -> ../bin/busybox were mistakenly dropped before. Co-authored-by: Andrew Fasano <fasano@mit.edu>
1 parent d013f69 commit 4d65832

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

unblob/handlers/archive/_safe_tarfile.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,9 @@ def extract(self, tarinfo: tarfile.TarInfo, extract_root: Path): # noqa: C901
8383
"Converted to extraction relative path.",
8484
)
8585
tarinfo.linkname = f"./{tarinfo.linkname}"
86-
if not is_safe_path(
87-
basedir=extract_root,
88-
path=extract_root / tarinfo.linkname,
89-
):
86+
87+
resolved_path = (extract_root / tarinfo.name).parent / tarinfo.linkname
88+
if not is_safe_path(basedir=extract_root, path=resolved_path):
9089
self.record_problem(
9190
tarinfo,
9291
"Traversal attempt through link path.",

0 commit comments

Comments
 (0)