Add new filter argument to extractdata method of tarfile when extracting tar files

This commit is contained in:
Théophile Diot 2024-03-14 15:08:18 +00:00
parent f1a2117a3c
commit afd2d456f3
No known key found for this signature in database
GPG key ID: 248FEA4BAE400D06
3 changed files with 5 additions and 5 deletions

View file

@ -137,10 +137,10 @@ try:
zf.extractall(path=temp_dir)
elif file_type == "application/gzip":
with tar_open(fileobj=BytesIO(content), mode="r:gz") as tar:
tar.extractall(path=temp_dir)
tar.extractall(path=temp_dir, filter="data")
elif file_type == "application/x-tar":
with tar_open(fileobj=BytesIO(content), mode="r") as tar:
tar.extractall(path=temp_dir)
tar.extractall(path=temp_dir, filter="data")
else:
LOGGER.error(f"Unknown file type for {plugin_url}, either zip or tar are supported, skipping...")
continue

View file

@ -134,7 +134,7 @@ def generate_external_plugins(plugins: List[Dict[str, Any]], *, original_path: U
tmp_path.parent.mkdir(parents=True, exist_ok=True)
tmp_path.write_bytes(plugin["data"])
with tar_open(str(tmp_path), "r:gz") as tar:
tar.extractall(original_path)
tar.extractall(original_path, filter="fully_trusted")
tmp_path.unlink()
for job_file in glob(join(str(tmp_path.parent), "jobs", "*")):

View file

@ -1135,7 +1135,7 @@ def plugins():
tar_file.getmember("plugin.json")
except KeyError:
is_dir = True
tar_file.extractall(str(temp_folder_path))
tar_file.extractall(str(temp_folder_path), filter="data")
except ReadError:
errors += 1
error = 1
@ -1339,7 +1339,7 @@ def upload_plugin():
if file.endswith("plugin.json"):
plugins.append(basename(dirname(file)))
if len(plugins) > 1:
tar_file.extractall(str(tmp_ui_path) + "/")
tar_file.extractall(str(tmp_ui_path) + "/", filter="data")
folder_name = uploaded_file.filename.replace(".tar.gz", "").replace(".tar.xz", "")
if len(plugins) <= 1: