From b41c54a40bc4b2bb458a51528afcf5848c1ae7c9 Mon Sep 17 00:00:00 2001 From: TrellixVulnTeam Date: Sun, 2 Oct 2022 15:57:41 +0000 Subject: [PATCH 1/2] Adding tarfile member sanitization to extractall() --- tools/dataset/preprocess_h36m.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/tools/dataset/preprocess_h36m.py b/tools/dataset/preprocess_h36m.py index 97f0edb5..ca25bd61 100644 --- a/tools/dataset/preprocess_h36m.py +++ b/tools/dataset/preprocess_h36m.py @@ -98,7 +98,26 @@ def extract_tgz(self): filename = join(cur_dir, file + '.tgz') print(f'Extracting {filename} ...') with tarfile.open(filename) as tar: - tar.extractall(self.extracted_dir) + def is_within_directory(directory, target): + + abs_directory = os.path.abspath(directory) + abs_target = os.path.abspath(target) + + prefix = os.path.commonprefix([abs_directory, abs_target]) + + return prefix == abs_directory + + def safe_extract(tar, path=".", members=None, *, numeric_owner=False): + + for member in tar.getmembers(): + member_path = os.path.join(path, member.name) + if not is_within_directory(path, member_path): + raise Exception("Attempted Path Traversal in Tar File") + + tar.extractall(path, members, numeric_owner) + + + safe_extract(tar, self.extracted_dir) print('Extraction done.\n') def generate_cameras_file(self): From 0dbda2748d0299dabfa1dda497ea974a8d7557bc Mon Sep 17 00:00:00 2001 From: TrellixVulnTeam Date: Tue, 4 Oct 2022 18:49:20 +0000 Subject: [PATCH 2/2] Adding numeric_owner as keyword arguement --- tools/dataset/preprocess_h36m.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/dataset/preprocess_h36m.py b/tools/dataset/preprocess_h36m.py index ca25bd61..e6e94dec 100644 --- a/tools/dataset/preprocess_h36m.py +++ b/tools/dataset/preprocess_h36m.py @@ -114,7 +114,7 @@ def safe_extract(tar, path=".", members=None, *, numeric_owner=False): if not is_within_directory(path, member_path): raise Exception("Attempted Path Traversal in Tar File") - tar.extractall(path, members, numeric_owner) + tar.extractall(path, members, numeric_owner=numeric_owner) safe_extract(tar, self.extracted_dir)