-
Notifications
You must be signed in to change notification settings - Fork 1.2k
fix: Fix the permission errors in Windows and add back the CVE-2007-4559 Patch changes #4580
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
Merged
hnnasit
merged 7 commits into
develop
from
revert-4560-revert-4539-revert-4535-revert-4499-develop
Jan 20, 2023
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
982230c
Revert "Revert "fix: Add back the fixed CVE-2007-4559 Patch changes (…
hnnasit 1e033e2
Merge branch 'develop' into revert-4560-revert-4539-revert-4535-rever…
hnnasit 003df29
Updated extract_tarfile to include fileobj as input parameter as well
hnnasit 2e65e3f
Merge branch 'develop' into revert-4560-revert-4539-revert-4535-rever…
hnnasit 04f431d
Added functional tests for file_obj kw arg
hnnasit 2785226
Merge branch 'develop' into revert-4560-revert-4539-revert-4535-rever…
hnnasit 36c20ac
Merge branch 'develop' into revert-4560-revert-4539-revert-4535-rever…
hnnasit File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| import os | ||
| import tempfile | ||
| import shutil | ||
| import platform | ||
| from pathlib import Path | ||
| from tarfile import ExtractError | ||
|
|
||
| from unittest import TestCase | ||
|
|
||
| from samcli.lib.utils.tar import extract_tarfile | ||
|
|
||
|
|
||
| class TestExtractTarFile(TestCase): | ||
| def test_extract_tarfile_arg_path_unpacks_a_tar(self): | ||
| test_tar = Path(__file__).resolve().parents[3].joinpath("functional", "testdata", "lib", "utils", "test.tgz") | ||
| test_dir = tempfile.mkdtemp() | ||
| extract_tarfile(tarfile_path=test_tar, unpack_dir=test_dir) | ||
| output_files = set(os.listdir(test_dir)) | ||
| shutil.rmtree(test_dir) | ||
| self.assertEqual({"test_utils.py"}, output_files) | ||
|
|
||
| def test_raise_exception_for_unsafe_tarfile_with_path_arg(self): | ||
| tar_filename = "path_reversal_win.tgz" if platform.system().lower() == "windows" else "path_reversal_uxix.tgz" | ||
| test_tar = Path(__file__).resolve().parents[3].joinpath("functional", "testdata", "lib", "utils", tar_filename) | ||
| test_dir = tempfile.mkdtemp() | ||
| self.assertRaisesRegex( | ||
| ExtractError, | ||
| "Attempted Path Traversal in Tar File", | ||
| extract_tarfile, | ||
| tarfile_path=test_tar, | ||
| unpack_dir=test_dir, | ||
| ) | ||
| shutil.rmtree(test_dir) | ||
|
|
||
| def test_extract_tarfile_arg_fileobj_unpacks_a_tar(self): | ||
| test_tar = Path(__file__).resolve().parents[3].joinpath("functional", "testdata", "lib", "utils", "test.tgz") | ||
| test_dir = tempfile.mkdtemp() | ||
| with open(test_tar, mode="rb") as tar: | ||
| before_extract_output_files = set(os.listdir(test_dir)) | ||
| self.assertEqual(set(), before_extract_output_files) | ||
| extract_tarfile(file_obj=tar, unpack_dir=test_dir) | ||
| after_extract_output_files = set(os.listdir(test_dir)) | ||
| self.assertEqual({"test_utils.py"}, after_extract_output_files) | ||
| shutil.rmtree(test_dir) | ||
|
|
||
| def test_raise_exception_for_unsafe_tarfile_with_flieobj_arg(self): | ||
| tar_filename = "path_reversal_win.tgz" if platform.system().lower() == "windows" else "path_reversal_uxix.tgz" | ||
| test_tar = Path(__file__).resolve().parents[3].joinpath("functional", "testdata", "lib", "utils", tar_filename) | ||
| test_dir = tempfile.mkdtemp() | ||
| with open(test_tar, mode="rb") as tar: | ||
| self.assertRaisesRegex( | ||
| ExtractError, | ||
| "Attempted Path Traversal in Tar File", | ||
| extract_tarfile, | ||
| file_obj=tar, | ||
| unpack_dir=test_dir, | ||
| ) | ||
| shutil.rmtree(test_dir) | ||
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.