This commit is contained in:
TrellixVulnTeam 2025-04-03 12:08:15 +00:00 committed by GitHub
commit 9416616d4f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -54,7 +54,26 @@ class LsfLauncher(Launcher):
log.info("[prepare_workspace]: [pyvenv]: Extracting %s",
Launcher.pyvenv)
with tarfile.open(Launcher.pyvenv, mode='r') as tar:
tar.extractall(args.scratch_root)
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, args.scratch_root)
log.info("[prepare_workspace]: [pyvenv]: Done: %s", path)
Launcher.pyvenv = path