comparison data_manager/data_manager.py @ 2:5408a9225788 draft default tip

planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_mitos commit 096286097ed5cdf189a1b68c3fc34d10f4142e54
author iuc
date Sun, 16 Apr 2023 08:27:55 +0000
parents 58bcd38cecb6
children
comparison
equal deleted inserted replaced
1:58bcd38cecb6 2:5408a9225788
52 finally: 52 finally:
53 if src: 53 if src:
54 src.close() 54 src.close()
55 with tarfile.open(tarfname, "r:bz2") as tar: 55 with tarfile.open(tarfname, "r:bz2") as tar:
56 dirname = tar.getnames()[0] 56 dirname = tar.getnames()[0]
57 tar.extractall(workdir) 57
58 def is_within_directory(directory, target):
59 abs_directory = os.path.abspath(directory)
60 abs_target = os.path.abspath(target)
61 prefix = os.path.commonprefix([abs_directory, abs_target])
62 return prefix == abs_directory
63
64 def safe_extract(tar, path=".", members=None, *, numeric_owner=False):
65 for member in tar.getmembers():
66 member_path = os.path.join(path, member.name)
67 if not is_within_directory(path, member_path):
68 raise Exception("Attempted Path Traversal in Tar File")
69 tar.extractall(path, members, numeric_owner=numeric_owner)
70
71 safe_extract(tar, workdir)
58 os.remove(tarfname) 72 os.remove(tarfname)
59 return dirname 73 return dirname
60 74
61 75
62 def main(tpe, db, outjson): 76 def main(tpe, db, outjson):