mirror of
https://github.com/anchore/syft.git
synced 2026-11-01 15:06:36 +01:00
Canonicalize Ghostscript CPE/PURL for ghostscript packages from PE Binaries (#4308)
* binary(pe): canonicalize Ghostscript CPE to artifex:ghostscript and add generic purl for PE (#4275)\n\n- Detect Ghostscript via PE version resources and set purl pkg:generic/ghostscript@<version>\n- Add PE-specific CPE candidates: vendor 'artifex', product 'ghostscript'\n- Add focused unit tests for purl and CPE generation Signed-off-by: kdt523 <krushna.datir231@vit.edu> * fix: gofmt formatting for static analysis pass (pe-ghostscript-cpe-purl-4275) Signed-off-by: kdt523 <krushna.datir231@vit.edu> --------- Signed-off-by: kdt523 <krushna.datir231@vit.edu>
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
packageurl "github.com/anchore/packageurl-go"
|
||||
"github.com/anchore/syft/syft/file"
|
||||
"github.com/anchore/syft/syft/pkg"
|
||||
)
|
||||
@@ -32,6 +33,19 @@ func newPEPackage(versionResources map[string]string, f file.Location) pkg.Packa
|
||||
Metadata: newPEBinaryVersionResourcesFromMap(versionResources),
|
||||
}
|
||||
|
||||
// If this appears to be Ghostscript, emit a canonical generic purl
|
||||
// Example expected: pkg:generic/ghostscript@<version>
|
||||
prod := strings.ToLower(spaceNormalize(versionResources["ProductName"]))
|
||||
if prod == "" {
|
||||
// fall back to FileDescription if ProductName is missing
|
||||
prod = strings.ToLower(spaceNormalize(versionResources["FileDescription"]))
|
||||
}
|
||||
if p.Version != "" && strings.Contains(prod, "ghostscript") {
|
||||
// build a generic PURL for ghostscript
|
||||
purl := packageurl.NewPackageURL(packageurl.TypeGeneric, "", "ghostscript", p.Version, nil, "").ToString()
|
||||
p.PURL = purl
|
||||
}
|
||||
|
||||
p.SetID()
|
||||
|
||||
return p
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package binary
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/anchore/syft/syft/file"
|
||||
)
|
||||
|
||||
func TestGhostscriptPEGeneratesGenericPURL(t *testing.T) {
|
||||
vr := map[string]string{
|
||||
"CompanyName": "Artifex Software, Inc.",
|
||||
"ProductName": "GPL Ghostscript",
|
||||
"FileDescription": "Ghostscript Interpreter",
|
||||
"ProductVersion": "9.54.0",
|
||||
}
|
||||
|
||||
loc := file.NewLocation("/usr/bin/gswin64c.exe")
|
||||
p := newPEPackage(vr, loc)
|
||||
|
||||
expected := "pkg:generic/ghostscript@9.54.0"
|
||||
if p.PURL != expected {
|
||||
t.Fatalf("expected purl %q, got %q", expected, p.PURL)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user