Skip to content
This repository was archived by the owner on Apr 26, 2023. It is now read-only.
Open
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
25 changes: 22 additions & 3 deletions get-gitzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def get_download_url(self):
with closing(urlopen(request)) as response:
data = json.loads(response.read())
tag_name = data["tag_name"].lstrip("v")
gzip_name = "gitzer-{}.tar.gz".format(tag_name)
gzip_name = f"gitzer-{tag_name}.tar.gz"
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Installer.get_download_url refactored with the following changes:

assets = data["assets"]
for asset in assets:
if asset["name"] == gzip_name:
Expand All @@ -65,7 +65,7 @@ def download_release(self):
r = urlopen(gzip_url)
except HTTPError as e:
if e.code == 404:
raise RuntimeError("Could not find {} file".format(gzip_name))
raise RuntimeError(f"Could not find {gzip_name} file")
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Installer.download_release refactored with the following changes:


meta = r.info()
size = int(meta["Content-Length"])
Expand Down Expand Up @@ -94,7 +94,26 @@ def install(self):
colored_print("INFO", f"Installing Gitzer to {str(GITZER_PATH)}...")
with tarfile.open(gitzer_tar, "r:gz") as tar_file:
temporary_dir = self.gitzer_temp_directory()
tar_file.extractall(temporary_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_file, temporary_dir)
os.makedirs(GITZER_HOME, exist_ok=True)
shutil.move(temporary_dir / "build", GITZER_PATH)
self.set_git_alias()
Expand Down