gromero commented on code in PR #13751:
URL: https://github.com/apache/tvm/pull/13751#discussion_r1066279559
##########
apps/microtvm/arduino/template_project/microtvm_api_server.py:
##########
@@ -177,11 +177,28 @@ def _remove_unused_components(self, source_dir,
project_type):
for component in unused_components:
shutil.rmtree(source_dir / "standalone_crt" / component)
+ def _safe_extract(tar, path=".", members=None, *, numeric_owner=False):
+ 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
+
+ for member in tar.getmembers():
+ member_path = os.path.join(path, member.name)
Review Comment:
Could we move this path join to `is_within_directory()` to make it just a
bit more self-contained?
##########
apps/microtvm/zephyr/template_project/microtvm_api_server.py:
##########
@@ -657,7 +657,26 @@ def generate_project(self, model_library_format_path,
standalone_crt_dir, projec
# Populate extra_files
if extra_files_tar:
with tarfile.open(extra_files_tar, mode="r:*") as tf:
- tf.extractall(project_dir)
+
+ 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")
Review Comment:
Same as above about adding the CVE #.
##########
apps/microtvm/zephyr/template_project/microtvm_api_server.py:
##########
@@ -657,7 +657,26 @@ def generate_project(self, model_library_format_path,
standalone_crt_dir, projec
# Populate extra_files
if extra_files_tar:
with tarfile.open(extra_files_tar, mode="r:*") as tf:
- tf.extractall(project_dir)
+
+ 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)
Review Comment:
Same as above about moving the join inside `is_within_directory()`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]