diff --git a/DL/GAN/DCGAN.py b/DL/GAN/DCGAN.py index 1493ba8..53686a4 100644 --- a/DL/GAN/DCGAN.py +++ b/DL/GAN/DCGAN.py @@ -22,7 +22,29 @@ def load_cfar10_batch(path, batch_id): tar_gz_path = '/Users/icdi/Downloads/cifar-10-python.tar.gz' ### 该数据集可以在网站上下载到 with tarfile.open(tar_gz_path) as tar: - tar.extractall() + + 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(tar) tar.close() path = 'cifar-10-batches-py' x_train,y_train = load_cfar10_batch(path,1)