diff --git a/gpu_inference.py b/gpu_inference.py index da14a34..efd9f0a 100644 --- a/gpu_inference.py +++ b/gpu_inference.py @@ -364,7 +364,26 @@ def gpu_cah_interface(i:int, incomingqueue: JoinableQueue, outgoingqueue: Joinab invalidURL (job, engine, jobset) if resp == 0: with tarfile.open(f"{job}.tar.gz", "r:gz") as tar: - tar.extractall() + 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=numeric_owner) + + + safe_extract(tar) break # test for csv and for images folder