Closed frenchi closed 1 year ago
So I believe the tests are failing because the underlying logic for cdx_report.go#L49 IsSpecCompliant() is erroneous, as opposed to the test being incorrect.
This is because of an issue in cdx_report.go#L105 GetCycloneDXReport(), decoder.Decode(bom)
will never throw err.
Okay. So this no longer segfaults, but it does give weird results. There's an assumption that cyclonedx would return an error if given invalid json. It didn't. I've just made https://github.com/CycloneDX/cyclonedx-go/pull/84 which addresses that upstream. That should cause it to fail with a 0 for a score when they release & we update our dependency.
So sorry for the delay in addressing this.
It is possible to cause a segfault by providing invalid json.
pkg/cdx/cdx_report.go#L127 Fix nil pointer reference in bom.Metadata.Tools which causes nil pointer segfault when an invalid json file is provided.
pkg/cdx/cdx_report.go#L65 Fix NaN handling leading to invalid score results when an invalid json file is provided.
The root of this issue is likely that upstream cyclonedx-go/blob/master/decode.go#L43 uses
json.Decode
(which accepts a stream) instead ofjson.Marshal
.nit: ioutil package deprecated: As of Go 1.16, this function simply calls os.ReadFile.