Skip to content

Commit

Permalink
Merge pull request #220 from TrellixVulnTeam/master
Browse files Browse the repository at this point in the history
  • Loading branch information
faustomorales committed Dec 24, 2022
2 parents 1d241e8 + 79ade8f commit b9c5a58
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion scripts/train_recognizer_synthtext90_multigpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,26 @@ def download_extract_and_process_dataset(data_path):
if not os.path.isdir(extraction_directory):
print("Extracting files.")
with tarfile.open(os.path.join(data_path, "mjsynth.tar.gz")) as tfile:
tfile.extractall(data_path)
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(tfile, data_path)


def get_image_generator(filepaths, augmenter, width, height):
Expand Down

0 comments on commit b9c5a58

Please sign in to comment.