@@ -262,45 +262,41 @@ def scan_file(self, filename: str) -> Iterator[ScanInfo]:
262
262
# check if it's a Linux kernel image
263
263
is_linux_kernel , output = self .is_linux_kernel (filename )
264
264
265
- # In no-scan mode, also check if it's a language-specific file
266
- is_language_file = False
267
- if self .no_scan :
268
- # Check if filename matches any language parser patterns
269
- for pattern in valid_files .keys ():
270
- if pattern in filename :
271
- is_language_file = True
272
- break
265
+ # Check if this file matches any language parser patterns
266
+ filename_basename = Path (filename ).name
267
+ is_language_file = filename_basename in self .language_checkers
273
268
269
+ # In no-scan mode, allow language files even if they're not binary
270
+ # In normal mode, require the file to be executable or a language file
274
271
if not is_exec and not is_linux_kernel and not is_language_file :
275
272
return None
276
273
277
- # parse binary file's strings
278
- lines = parse_strings (filename )
274
+ # parse binary file's strings (only for binary files)
275
+ lines = ""
276
+ if is_exec or is_linux_kernel :
277
+ lines = parse_strings (filename )
279
278
280
279
if not self .no_scan and not self .cve_db :
281
280
self .logger .info ("No Database Object Found: Fallback to No-Scan Mode" )
282
281
283
- if output :
282
+ # Check for language parsers first
283
+ if output or is_language_file :
284
284
valid_file = False
285
285
for file in list (self .language_checkers .keys ()):
286
- valid_file = valid_file | (file in output )
286
+ valid_file = (
287
+ valid_file | (file in output )
288
+ if output
289
+ else (file == filename_basename )
290
+ )
287
291
if valid_file :
288
- for scan_info in parse (filename , output , self .cve_db , self .logger ):
292
+ for scan_info in parse (
293
+ filename , output or "" , self .cve_db , self .logger
294
+ ):
289
295
yield ScanInfo (scan_info .product_info , "" .join (self .file_stack ))
290
296
291
- # In no-scan mode, also try to parse language-specific files directly
292
- if self .no_scan and is_language_file :
293
- # Create a mock output string that includes the filename pattern
294
- for pattern in valid_files .keys ():
295
- if pattern in filename :
296
- mock_output = f"mock: { pattern } "
297
- for scan_info in parse (
298
- filename , mock_output , self .cve_db , self .logger
299
- ):
300
- yield ScanInfo (scan_info .product_info , "" .join (self .file_stack ))
301
- break
302
-
303
- yield from self .run_checkers (filename , lines )
297
+ # Only run binary checkers on binary files
298
+ if is_exec or is_linux_kernel :
299
+ yield from self .run_checkers (filename , lines )
304
300
305
301
def run_checkers (self , filename : str , lines : str ) -> Iterator [ScanInfo ]:
306
302
"""process a Set of checker objects, run them on file lines,
0 commit comments