comparison data_manager/data_manager_qiime_download.py @ 4:c4dba88e85ef draft default tip

planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/data_managers/data_manager_qiime_database_downloader commit 09b56ef3e09ad6c5923c88616fea5cbd77d87616
author iuc
date Mon, 18 Dec 2023 09:36:52 +0000
parents cc18f0f3514c
children
comparison
equal deleted inserted replaced
3:cc18f0f3514c 4:c4dba88e85ef
181 """ 181 """
182 """ 182 """
183 archive_content_path = "tmp" 183 archive_content_path = "tmp"
184 if ext == "tar.gz" or ext == "tgz": 184 if ext == "tar.gz" or ext == "tgz":
185 with tarfile.open(filepath) as tar: 185 with tarfile.open(filepath) as tar:
186 tar.extractall(path=archive_content_path) 186 def is_within_directory(directory, target):
187 abs_directory = os.path.abspath(directory)
188 abs_target = os.path.abspath(target)
189 prefix = os.path.commonprefix([abs_directory, abs_target])
190 return prefix == abs_directory
191
192 def safe_extract(tar, path=".", members=None, *, numeric_owner=False):
193 for member in tar.getmembers():
194 member_path = os.path.join(path, member.name)
195 if not is_within_directory(path, member_path):
196 raise Exception("Attempted Path Traversal in Tar File")
197 tar.extractall(path, members, numeric_owner=numeric_owner)
198
199 safe_extract(tar, path=archive_content_path)
187 archive_content_path = find_archive_content_path(archive_content_path) 200 archive_content_path = find_archive_content_path(archive_content_path)
188 elif ext == "zip": 201 elif ext == "zip":
189 with zipfile.ZipFile(filepath, 'r') as zip_ref: 202 with zipfile.ZipFile(filepath, 'r') as zip_ref:
190 zip_ref.extractall(archive_content_path) 203 zip_ref.extractall(archive_content_path)
191 archive_content_path = find_archive_content_path(archive_content_path) 204 archive_content_path = find_archive_content_path(archive_content_path)