mirror of
https://github.com/kennethreitz/pipenv.git
synced 2026-06-05 22:50:18 +00:00
@@ -146,7 +146,26 @@ def test_local_package(pipenv_instance_private_pypi, pip_src_dir, testsroot):
|
||||
import tarfile
|
||||
|
||||
with tarfile.open(copy_to, "r:gz") as tgz:
|
||||
tgz.extractall(path=p.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)
|
||||
|
||||
|
||||
safe_extract(tgz, path=p.path)
|
||||
c = p.pipenv(f"install -e {package}")
|
||||
assert c.returncode == 0
|
||||
assert all(
|
||||
|
||||
Reference in New Issue
Block a user