Skip to content

refactor(extractor): Prioritize 7z while extracting pkg files in windows #1689

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
merged 2 commits into from
Jun 16, 2022
Merged
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: 19 additions & 6 deletions cve_bin_tool/extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,24 @@ async def extract_file_zst(self, filename: str, extraction_path: str) -> int:
async def extract_file_pkg(self, filename: str, extraction_path: str) -> int:
"""Extract pkg files"""

async def _extract_through_7z() -> int:
"""Extract file using `7z`"""

temp = os.path.join(self.tempdir, f"{os.path.basename(filename)}")
stdout, stderr, _ = await aio_run_command(
["7z", "x", filename, f"-o{self.tempdir}"]
)
stdout, stderr, _ = await aio_run_command(
["7z", "x", temp[:-4], f"-o{extraction_path}"]
)
if not stdout:
return 1
return 0

if sys.platform.startswith("win"):
if await aio_inpath("7z"):
return await _extract_through_7z()

# Tarfile wasn't used here because it can't open [.pkg] files directy
# and failed to manage distinct compression types in differnet versions of FreeBSD packages.
# Reference: https://github.com/intel/cve-bin-tool/pull/1580#discussion_r829346602
Expand All @@ -139,12 +157,7 @@ async def extract_file_pkg(self, filename: str, extraction_path: str) -> int:
return 1
return 0
if await aio_inpath("7z"):
stdout, stderr, _ = await aio_run_command(
["7z", "x", filename, "-o", extraction_path]
)
if stderr or not stdout:
return 1
return 0
return await _extract_through_7z()
return 1

async def extract_file_deb(self, filename, extraction_path):
Expand Down