@@ -91,7 +91,7 @@ def cache_update(cachedir, url, sha, chunk_size=16 * 1024, logger=LOGGER):
91
91
"""
92
92
Update the cache for a single year of NVD data.
93
93
"""
94
- filename = url .split ("/" )[- 1 ]. replace ( ".gz" , "" )
94
+ filename = url .split ("/" )[- 1 ]
95
95
# Ensure we only write to files within the cachedir
96
96
filepath = os .path .abspath (os .path .join (cachedir , filename ))
97
97
if not filepath .startswith (os .path .abspath (cachedir )):
@@ -101,7 +101,7 @@ def cache_update(cachedir, url, sha, chunk_size=16 * 1024, logger=LOGGER):
101
101
# Validate the sha and write out
102
102
sha = sha .upper ()
103
103
calculate = hashlib .sha256 ()
104
- with open (filepath , "rb" ) as handle :
104
+ with gzip . open (filepath , "rb" ) as handle :
105
105
chunk = handle .read (chunk_size )
106
106
while chunk :
107
107
calculate .update (chunk )
@@ -127,7 +127,7 @@ def cache_update(cachedir, url, sha, chunk_size=16 * 1024, logger=LOGGER):
127
127
sha = sha .upper ()
128
128
calculate = hashlib .sha256 ()
129
129
# Copy the contents while updating the sha
130
- with open (filepath , "wb" ) as filepath_handle :
130
+ with gzip . open (filepath , "wb" ) as filepath_handle :
131
131
chunk = jsondata_fileobj .read (chunk_size )
132
132
while chunk :
133
133
calculate .update (chunk )
@@ -149,7 +149,7 @@ class CVEDB(object):
149
149
CACHEDIR = DISK_LOCATION_DEFAULT
150
150
FEED = "https://nvd.nist.gov/vuln/data-feeds"
151
151
LOGGER = LOGGER .getChild ("CVEDB" )
152
- NVDCVE_FILENAME_TEMPLATE = "nvdcve-1.1-{}.json"
152
+ NVDCVE_FILENAME_TEMPLATE = "nvdcve-1.1-{}.json.gz "
153
153
META_REGEX = re .compile (r"https:\/\/.*\/json\/.*-[0-9]*\.[0-9]*-[0-9]*\.meta" )
154
154
RANGE_UNSET = ""
155
155
@@ -558,7 +558,7 @@ def year(self, year):
558
558
if not os .path .isfile (filename ):
559
559
raise CVEDataForYearNotInCache (year )
560
560
# Open the file and load the JSON data, log the number of CVEs loaded
561
- with open (filename , "rb" ) as fileobj :
561
+ with gzip . open (filename , "rb" ) as fileobj :
562
562
cves_for_year = json .load (fileobj )
563
563
self .LOGGER .debug (
564
564
f'Year { year } has { len (cves_for_year ["CVE_Items" ])} CVEs in dataset'
@@ -571,9 +571,9 @@ def years(self):
571
571
"""
572
572
return sorted (
573
573
[
574
- int (filename .split ("." )[- 2 ].split ("-" )[- 1 ])
574
+ int (filename .split ("." )[- 3 ].split ("-" )[- 1 ])
575
575
for filename in glob .glob (
576
- os .path .join (self .cachedir , "nvdcve-1.1-*.json" )
576
+ os .path .join (self .cachedir , "nvdcve-1.1-*.json.gz " )
577
577
)
578
578
]
579
579
)
0 commit comments