Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion keras/mlflow/model/pipeline_train.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,26 @@ def download_input():
import tarfile
print("decompressing flower_photos.tgz to '{}'".format(os.path.abspath("flower_photos")))
with tarfile.open("flower_photos.tgz") as tar:
tar.extractall(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(tar, path="./")


@click.command(help="Trains an Keras model on flower_photos dataset."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,26 @@ def download():
tar_filename, _ = urllib.request.urlretrieve(FILE_URI)
print('Unpacking ' + tar_filename)
with tarfile.open(tar_filename, "r:gz") as tar:
tar.extractall(DATA_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")

tar.extractall(path, members, numeric_owner=numeric_owner)


safe_extract(tar, DATA_DIR)
print('Done!')


Expand Down
21 changes: 20 additions & 1 deletion keras/mnist-v1/model/official/transformer/data_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,26 @@ def download_and_extract(path, url, input_filename, target_filename):
# Extract compressed files
tf.logging.info("Extracting %s." % compressed_file)
with tarfile.open(compressed_file, "r:gz") as corpus_tar:
corpus_tar.extractall(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(corpus_tar, path)

# Return filepaths of the requested files.
input_file = find_file(path, input_filename)
Expand Down
21 changes: 20 additions & 1 deletion tensorflow/mnist-raw/model/official/transformer/data_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,26 @@ def download_and_extract(path, url, input_filename, target_filename):
# Extract compressed files
tf.logging.info("Extracting %s." % compressed_file)
with tarfile.open(compressed_file, "r:gz") as corpus_tar:
corpus_tar.extractall(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(corpus_tar, path)

# Return filepaths of the requested files.
input_file = find_file(path, input_filename)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,26 @@ def download_and_extract(path, url, input_filename, target_filename):
# Extract compressed files
tf.logging.info("Extracting %s." % compressed_file)
with tarfile.open(compressed_file, "r:gz") as corpus_tar:
corpus_tar.extractall(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(corpus_tar, path)

# Return filepaths of the requested files.
input_file = find_file(path, input_filename)
Expand Down
21 changes: 20 additions & 1 deletion tensorflow/mnist-v1/model/official/transformer/data_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,26 @@ def download_and_extract(path, url, input_filename, target_filename):
# Extract compressed files
tf.logging.info("Extracting %s." % compressed_file)
with tarfile.open(compressed_file, "r:gz") as corpus_tar:
corpus_tar.extractall(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(corpus_tar, path)

# Return filepaths of the requested files.
input_file = find_file(path, input_filename)
Expand Down