@@ -74,7 +74,23 @@ def get_affected_version(self, data, osv_id):
7474 def get_findings (self , scan_file , test ):
7575 findings = []
7676 try :
77- data = json .load (scan_file )
77+ try :
78+ data = json .load (scan_file )
79+ except json .JSONDecodeError :
80+ scan_file .seek (0 )
81+ data = []
82+ buf = ""
83+ for line in scan_file :
84+ if not line .strip ():
85+ continue
86+ buf += line .decode ("utf-8" ) if isinstance (line , bytes ) else line
87+ try :
88+ data .append (json .loads (buf ))
89+ buf = ""
90+ except json .JSONDecodeError :
91+ continue
92+ if not data :
93+ raise ValueError
7894 except Exception :
7995 msg = "Invalid JSON format"
8096 raise ValueError (msg )
@@ -160,7 +176,7 @@ def get_findings(self, scan_file, test):
160176 range_info = "\n " .join (formatted_ranges )
161177
162178 vuln_functions = ", " .join (
163- set (osv_data ["affected" ][0 ][ "ecosystem_specific" ][ "imports" ] [0 ].get ("symbols" , [])),
179+ set (osv_data ["affected" ][0 ]. get ( "ecosystem_specific" , {}). get ( "imports" , [{}]) [0 ].get ("symbols" , [])),
164180 )
165181
166182 description = (
@@ -172,7 +188,7 @@ def get_findings(self, scan_file, test):
172188 f"**Traces found :**\n { self .get_finding_trace_info (data , osv_data ['id' ])} "
173189 )
174190
175- references = [f"{ ref ['type' ]} : { ref ['url' ]} " for ref in osv_data [ "references" ] ]
191+ references = [f"{ ref ['type' ]} : { ref ['url' ]} " for ref in osv_data . get ( "references" , []) ]
176192 db_specific_url = osv_data ["database_specific" ].get ("url" , "Unknown" )
177193 if db_specific_url :
178194 references .append (f"Database: { db_specific_url } " )
0 commit comments