Skip to content

Commit

Permalink
Merge pull request #4 from TrellixVulnTeam/main
Browse files Browse the repository at this point in the history
  • Loading branch information
janhohenheim authored Oct 22, 2022
2 parents 5f8ea58 + a614a14 commit 10a1d0d
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion install_majoras_mask_3d/citra.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,26 @@ def _install_citra(url, citra_directory):
file_path = os.path.join(temp_directory, f"citra.tar.gz")
download_file(url, file_path)
with tarfile.open(file_path, "r:gz") as tar:
tar.extractall(temp_directory)
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, temp_directory)
temp_citra_directory = get_only_subdirectory_path(temp_directory)
copytree(temp_citra_directory, citra_directory, dirs_exist_ok=True)

Expand Down

0 comments on commit 10a1d0d

Please sign in to comment.