chainguard-dev / malcontent

detect malicious program behaviors
Apache License 2.0
407 stars 26 forks source link

Check if frs Map is nil before ranging over it #462

Closed egibs closed 2 weeks ago

egibs commented 2 weeks ago

Closes https://github.com/chainguard-dev/bincapz/issues/458

The .jar file in the aforementioned issue failed to extract:

time=2024-09-15T21:08:02.374-04:00 level=ERROR source=/Users/t/src/bincapz/pkg/action/scan.go:233 msg="unable to process ../malware/Downloads/909a19d0de5476e249c133f73c4afa288982d05dcf4ca597fa8357d93f435c47.jar: extract to temp: failed to extract ../malware/Downloads/909a19d0de5476e249c133f73c4afa288982d05dcf4ca597fa8357d93f435c47.jar: failed to open zip file ../malware/Downloads/909a19d0de5476e249c133f73c4afa288982d05dcf4ca597fa8357d93f435c47.jar: zip: not a valid zip file"

Which means the frs Map was not populated (i.e., was still nil) before we tried to use the Range() method (and we're passing in a pointer to the Map via frs *sync.Map):

frs.Range(func(_, value any) bool {
    ...
}

This PR should handle cases like this more resiliently.