Skip to content
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

Fix the vulnerability #133

Merged
merged 2 commits into from
Aug 25, 2023
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ beautifulsoup4
jsonmerge
spdx-tools==0.7.0rc0
npm
setuptools>=65.5.1 # not directly required, pinned by Snyk to avoid a vulnerability
setuptools>=65.5.1 # not directly required, pinned by Snyk to avoid a vulnerability
numpy>=1.22.2
4 changes: 2 additions & 2 deletions src/fosslight_util/_get_downloadable_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def get_downloadable_url(link):
ret, new_link = get_download_location_for_pypi(link)
elif link.startswith('mvnrepository.com/artifact/') or link.startswith('repo1.maven.org/'):
ret, new_link = get_download_location_for_maven(link)
elif link.startswith('www.npmjs.com/') or link.startswith('registry.npmjs.org'):
elif link.startswith('www.npmjs.com/') or link.startswith('registry.npmjs.org/'):
ret, new_link = get_download_location_for_npm(link)
elif link.startswith('pub.dev/'):
ret, new_link = get_download_location_for_pub(link)
Expand Down Expand Up @@ -118,7 +118,7 @@ def get_download_location_for_npm(link):
oss_name_npm = ""
tar_name = ""

if link.startswith('www.npmjs.com/') or link.startswith('registry.npmjs.org'):
if link.startswith('www.npmjs.com/') or link.startswith('registry.npmjs.org/'):
try:
dn_loc_split = link.split('/')
if dn_loc_split[1] == 'package':
Expand Down
14 changes: 7 additions & 7 deletions src/fosslight_util/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import shutil
import pygit2 as git
import bz2
import contextlib
from datetime import datetime
from pathlib import Path
from fosslight_util._get_downloadable_url import get_downloadable_url
Expand Down Expand Up @@ -282,13 +283,11 @@ def extract_compressed_file(fname, extract_path, remove_after_extract=True):
fname = os.path.splitext(fname)[0]

if fname.endswith(".tar.gz") or fname.endswith(".tgz"):
tar = tarfile.open(fname, "r:gz")
tar.extractall(path=extract_path)
tar.close()
with contextlib.closing(tarfile.open(fname, "r:gz")) as t:
t.extractall(path=extract_path)
elif fname.endswith(".tar.xz") or fname.endswith(".tar"):
tar = tarfile.open(fname, "r:*")
tar.extractall(path=extract_path)
tar.close()
with contextlib.closing(tarfile.open(fname, "r:*")) as t:
t.extractall(path=extract_path)
elif fname.endswith(".zip") or fname.endswith(".jar"):
unzip(fname, extract_path)
elif fname.endswith(".bz2"):
Expand All @@ -313,7 +312,8 @@ def decompress_bz2(source_file, dest_path):
try:
fzip = bz2.BZ2File(source_file)
data = fzip.read() # get the decompressed data
open(os.path.splitext(source_file)[0], 'wb').write(data) # write a uncompressed file
with open(os.path.splitext(source_file)[0], 'wb') as f:
f.write(data) # write a uncompressed file

except Exception as error:
logger.error(f"Decompress bz2 - failed: {error}")
Expand Down
Loading