Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
* Adding tarfile member sanitization to extractall()

* Update download_data.py

formatting issues

* Update download_data.py

More

* Update download_data.py

* Update download_data.py

* Update download_data.py

Co-authored-by: ad-daniel <44834743+ad-daniel@users.noreply.github.com>
  • Loading branch information
TrellixVulnTeam and ad-daniel authored Nov 15, 2022
1 parent 5bceae4 commit ab952ff
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions projects/simulation/SMPL+D_human_models/src/download_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,24 @@ def reporthook(count, block_size, total_size):
start_time = 0
last_print = 0
urlretrieve(human_data_url, downloaded_human_data_path, reporthook=reporthook)

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)

with tarfile.open(downloaded_human_data_path) as tar:
tar.extractall(path=os.path.join(OPENDR_HOME, 'projects/simulation/SMPL+D_human_models'))
safe_extract(tar, path=os.path.join(OPENDR_HOME, 'projects/simulation/SMPL+D_human_models'))
tar.close()
os.remove(downloaded_human_data_path)

Expand All @@ -64,7 +80,7 @@ def reporthook(count, block_size, total_size):
last_print = 0
urlretrieve(model_url, downloaded_model_path, reporthook=reporthook)
with tarfile.open(downloaded_model_path) as tar:
tar.extractall(path=os.path.join(OPENDR_HOME, 'projects/simulation/SMPL+D_human_models'))
safe_extract(tar, path=os.path.join(OPENDR_HOME, 'projects/simulation/SMPL+D_human_models'))
tar.close()
os.remove(downloaded_model_path)

Expand Down

0 comments on commit ab952ff

Please sign in to comment.