diff --git a/tensorflow_chatbot-master/tensorflow_chatbot-master/new_data_util.py b/tensorflow_chatbot-master/tensorflow_chatbot-master/new_data_util.py index 53a85df..cb3c44e 100644 --- a/tensorflow_chatbot-master/tensorflow_chatbot-master/new_data_util.py +++ b/tensorflow_chatbot-master/tensorflow_chatbot-master/new_data_util.py @@ -80,7 +80,26 @@ def get_wmt_enfr_train_set(directory): _WMT_ENFR_TRAIN_URL) print("Extracting tar file %s" % corpus_file) with tarfile.open(corpus_file, "r") as corpus_tar: - corpus_tar.extractall(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(corpus_tar, directory) gunzip_file(train_path + ".fr.gz", train_path + ".fr") gunzip_file(train_path + ".en.gz", train_path + ".en") return train_path diff --git "a/tf_chatbot_seq2seq_antilm-master_\345\216\237\345\247\213/tf_chatbot_seq2seq_antilm-master/lib/data_utils.py" "b/tf_chatbot_seq2seq_antilm-master_\345\216\237\345\247\213/tf_chatbot_seq2seq_antilm-master/lib/data_utils.py" index a2d162e..2173892 100644 --- "a/tf_chatbot_seq2seq_antilm-master_\345\216\237\345\247\213/tf_chatbot_seq2seq_antilm-master/lib/data_utils.py" +++ "b/tf_chatbot_seq2seq_antilm-master_\345\216\237\345\247\213/tf_chatbot_seq2seq_antilm-master/lib/data_utils.py" @@ -83,7 +83,29 @@ def get_wmt_enfr_train_set(directory): _WMT_ENFR_TRAIN_URL) print("Extracting tar file %s" % corpus_file) with tarfile.open(corpus_file, "r") as corpus_tar: - corpus_tar.extractall(directory) + + import os + + 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, directory) gunzip_file(train_path + ".fr.gz", train_path + ".fr") gunzip_file(train_path + ".en.gz", train_path + ".en") return train_path diff --git "a/tf_chatbot_seq2seq_antilm-master_\345\216\237\345\247\213/tf_chatbot_seq2seq_antilm-master/ref/data_utils.py" "b/tf_chatbot_seq2seq_antilm-master_\345\216\237\345\247\213/tf_chatbot_seq2seq_antilm-master/ref/data_utils.py" index 2acab8d..75ac16c 100644 --- "a/tf_chatbot_seq2seq_antilm-master_\345\216\237\345\247\213/tf_chatbot_seq2seq_antilm-master/ref/data_utils.py" +++ "b/tf_chatbot_seq2seq_antilm-master_\345\216\237\345\247\213/tf_chatbot_seq2seq_antilm-master/ref/data_utils.py" @@ -80,7 +80,26 @@ def get_wmt_enfr_train_set(directory): _WMT_ENFR_TRAIN_URL) print("Extracting tar file %s" % corpus_file) with tarfile.open(corpus_file, "r") as corpus_tar: - corpus_tar.extractall(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(corpus_tar, directory) gunzip_file(train_path + ".fr.gz", train_path + ".fr") gunzip_file(train_path + ".en.gz", train_path + ".en") return train_path