-
Notifications
You must be signed in to change notification settings - Fork 84
CVE-2007-4559 Patch #47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -44,7 +44,26 @@ def _do_extraction(destination_folder, file, file_ending, verbose): | |
| z.extractall(path=os.path.abspath(destination_folder)) | ||
| elif file_ending == "7z": | ||
| with lzma.open(file) as z: | ||
| z.extractall(path=destination_folder) | ||
| def is_within_directory(directory, target): | ||
|
|
||
| abs_directory = os.path.abspath(directory) | ||
| abs_target = os.path.abspath(target) | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Blank line contains whitespace |
||
| prefix = os.path.commonprefix([abs_directory, abs_target]) | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Blank line contains whitespace |
||
| return prefix == abs_directory | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Blank line contains whitespace |
||
| def safe_extract(tar, path=".", members=None, *, numeric_owner=False): | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Blank line contains whitespace |
||
| 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(z, path=destination_folder) | ||
| else: | ||
| if verbose: | ||
| print(colored("Not a supported archive type!", "red")) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Blank line contains whitespace