diff --git a/windowsbuild/MSVC2017/python/3.7.7/Lib/site-packages/Pygments-2.5.2-py3.7.egg/pygments/lexers/_php_builtins.py b/windowsbuild/MSVC2017/python/3.7.7/Lib/site-packages/Pygments-2.5.2-py3.7.egg/pygments/lexers/_php_builtins.py index 44ef20530..541314568 100644 --- a/windowsbuild/MSVC2017/python/3.7.7/Lib/site-packages/Pygments-2.5.2-py3.7.egg/pygments/lexers/_php_builtins.py +++ b/windowsbuild/MSVC2017/python/3.7.7/Lib/site-packages/Pygments-2.5.2-py3.7.egg/pygments/lexers/_php_builtins.py @@ -4728,7 +4728,26 @@ def get_php_functions(): def get_php_references(): download = urlretrieve(PHP_MANUAL_URL) with tarfile.open(download[0]) as tar: - tar.extractall() + 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) for file in glob.glob("%s%s" % (PHP_MANUAL_DIR, PHP_REFERENCE_GLOB)): yield file os.remove(download[0]) diff --git a/windowsbuild/MSVC2017/python/3.7.7/Lib/tarfile.py b/windowsbuild/MSVC2017/python/3.7.7/Lib/tarfile.py index 3b596cbf4..3a2b89391 100644 --- a/windowsbuild/MSVC2017/python/3.7.7/Lib/tarfile.py +++ b/windowsbuild/MSVC2017/python/3.7.7/Lib/tarfile.py @@ -2496,7 +2496,26 @@ def main(): if is_tarfile(src): with TarFile.open(src, 'r:*') as tf: - tf.extractall(path=curdir) + 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(tf, path=curdir) if args.verbose: if curdir == '.': msg = '{!r} file is extracted.'.format(src) diff --git a/windowsbuild/MSVC2017/python/3.7.7/Lib/test/test_tarfile.py b/windowsbuild/MSVC2017/python/3.7.7/Lib/test/test_tarfile.py index 5e4d75ecf..0d1e73f3e 100644 --- a/windowsbuild/MSVC2017/python/3.7.7/Lib/test/test_tarfile.py +++ b/windowsbuild/MSVC2017/python/3.7.7/Lib/test/test_tarfile.py @@ -604,7 +604,26 @@ def test_extractall_pathlike_name(self): with support.temp_dir(DIR), \ tarfile.open(tarname, encoding="iso8859-1") as tar: directories = [t for t in tar if t.isdir()] - tar.extractall(DIR, directories) + 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, DIR, directories) for tarinfo in directories: path = DIR / tarinfo.name self.assertEqual(os.path.getmtime(path), tarinfo.mtime)