From ff6c34de7ef2a7d47f259997c7f9e39116f9eaeb Mon Sep 17 00:00:00 2001 From: witchcraze <67056980+witchcraze@users.noreply.github.com> Date: Tue, 21 Apr 2026 01:23:35 +0900 Subject: [PATCH] fix: improve haskell classifiers (#4793) Signed-off-by: witchcraze --- .../binary/classifier_cataloger_test.go | 33 ++++++++++++++++++ syft/pkg/cataloger/binary/classifiers.go | 21 ++++++++--- .../haskell-cabal/1.22.6.0/linux-amd64/cabal | Bin 0 -> 350 bytes .../haskell-ghc/7.10.3/linux-amd64/ghc | Bin 0 -> 345 bytes .../haskell-ghc/8.10.4/linux-amd64/ghc | Bin 0 -> 345 bytes .../pkg/cataloger/binary/testdata/config.yaml | 26 ++++++++++++++ 6 files changed, 76 insertions(+), 4 deletions(-) create mode 100644 syft/pkg/cataloger/binary/testdata/classifiers/snippets/haskell-cabal/1.22.6.0/linux-amd64/cabal create mode 100644 syft/pkg/cataloger/binary/testdata/classifiers/snippets/haskell-ghc/7.10.3/linux-amd64/ghc create mode 100644 syft/pkg/cataloger/binary/testdata/classifiers/snippets/haskell-ghc/8.10.4/linux-amd64/ghc diff --git a/syft/pkg/cataloger/binary/classifier_cataloger_test.go b/syft/pkg/cataloger/binary/classifier_cataloger_test.go index 6d9e23f1a..05b25121a 100644 --- a/syft/pkg/cataloger/binary/classifier_cataloger_test.go +++ b/syft/pkg/cataloger/binary/classifier_cataloger_test.go @@ -1364,6 +1364,28 @@ func Test_Cataloger_PositiveCases(t *testing.T) { Metadata: metadata("deno-binary"), }, }, + { + logicalFixture: "haskell-ghc/7.10.3/linux-amd64", + expected: pkg.Package{ + Name: "haskell/ghc", + Version: "7.10.3", + Type: "binary", + PURL: "pkg:generic/haskell/ghc@7.10.3", + Locations: locations("ghc"), + Metadata: metadata("haskell-ghc-binary"), + }, + }, + { + logicalFixture: "haskell-ghc/8.10.4/linux-amd64", + expected: pkg.Package{ + Name: "haskell/ghc", + Version: "8.10.4", + Type: "binary", + PURL: "pkg:generic/haskell/ghc@8.10.4", + Locations: locations("ghc"), + Metadata: metadata("haskell-ghc-binary"), + }, + }, { logicalFixture: "haskell-ghc/9.6.5/linux-amd64", expected: pkg.Package{ @@ -1375,6 +1397,17 @@ func Test_Cataloger_PositiveCases(t *testing.T) { Metadata: metadata("haskell-ghc-binary"), }, }, + { + logicalFixture: "haskell-cabal/1.22.6.0/linux-amd64", + expected: pkg.Package{ + Name: "haskell/cabal", + Version: "1.22.6.0", + Type: "binary", + PURL: "pkg:generic/haskell/cabal@1.22.6.0", + Locations: locations("cabal"), + Metadata: metadata("haskell-cabal-binary"), + }, + }, { logicalFixture: "haskell-cabal/3.10.3.0/linux-amd64", expected: pkg.Package{ diff --git a/syft/pkg/cataloger/binary/classifiers.go b/syft/pkg/cataloger/binary/classifiers.go index e5a3e2f4e..65f24e666 100644 --- a/syft/pkg/cataloger/binary/classifiers.go +++ b/syft/pkg/cataloger/binary/classifiers.go @@ -438,8 +438,15 @@ func DefaultClassifiers() []binutils.Classifier { { Class: "haskell-ghc-binary", FileGlob: "**/ghc*", - EvidenceMatcher: m.FileContentsVersionMatcher( - `(?m)\x00GHC (?P[0-9]+\.[0-9]+\.[0-9]+)\x00`, + EvidenceMatcher: binutils.MatchAny( + m.FileContentsVersionMatcher( + `(?m)\x00GHC (?P[0-9]+\.[0-9]+\.[0-9]+)\x00`, + ), + m.FileContentsVersionMatcher( + // [NUL]libHSghc-7.10.3-0AG9TOjDEtx4Ji3wSwHOBe-ghc7.10.3.so[NUL] + // [NUL]libHSghc-8.10.4-ghc8.10.4.so[NUL] + `\x00libHSghc\-(?P[0-9]+\.[0-9]+\.[0-9]+)\-([a-zA-Z0-9]+\-)?ghc[0-9]+\.[0-9]+\.[0-9]+\.so\x00`, + ), ), Package: "haskell/ghc", PURL: mustPURL("pkg:generic/haskell/ghc@version"), @@ -448,8 +455,14 @@ func DefaultClassifiers() []binutils.Classifier { { Class: "haskell-cabal-binary", FileGlob: "**/cabal", - EvidenceMatcher: m.FileContentsVersionMatcher( - `(?m)\x00Cabal-(?P[0-9]+\.[0-9]+\.[0-9]+(\.[0-9]+)?)-`, + EvidenceMatcher: binutils.MatchAny( + m.FileContentsVersionMatcher( + `(?m)\x00Cabal-(?P[0-9]+\.[0-9]+\.[0-9]+(\.[0-9]+)?)-`, + ), + m.FileContentsVersionMatcher( + // [NUL][NUL][NUL]/opt/cabal/1.22/lib/x86_64-linux-ghc-7.10.2/cabal-install-1.22.6.0-AfxbHivcmw40BMGrAXG3jJ[NUL][NUL][NUL] + `\x00.{0,50}cabal\-install\-(?P[0-9]+\.[0-9]+\.[0-9]+(\.[0-9]+)?)\-[a-zA-Z0-9]+\x00+`, + ), ), Package: "haskell/cabal", PURL: mustPURL("pkg:generic/haskell/cabal@version"), diff --git a/syft/pkg/cataloger/binary/testdata/classifiers/snippets/haskell-cabal/1.22.6.0/linux-amd64/cabal b/syft/pkg/cataloger/binary/testdata/classifiers/snippets/haskell-cabal/1.22.6.0/linux-amd64/cabal new file mode 100644 index 0000000000000000000000000000000000000000..8a1534ed23c8a4fc3aeec8f00f17b93522c0ca1f GIT binary patch literal 350 zcmXw!yKVw86hu?|D=bm(?!A7Sjx>}6%^7mQtm~v)xG&9mMuX&_E zjZLLo^1S8<&N}ddwLI?U!(s?vm$9Bsd44^R&}PlE*8!v}0+rPUV^kisrV?b<){7uL zg`@}oDSDX`CRr@12;`+V*|Abv{)ZI^5k*MSJDUW?L=sBY+60oA5(uf1BSEPY%-)ok zov^VeYX}tt$=GVO;^Aw~{BI_oCtjx3rYm0})^>Hg%+%Vh)sX7>VbL(1=Hch~fV~jI zk_;4$sz22K1x=p!-r}`O>R|StR+w(yigb% zS}lSLQ8`srtJR9QYe8~9laz_XX&9ypS*mKvBj(a}Sho3_wkgNyX-IB=Tz+2b4TTL~ z!}HFZ4xew^@*_SHzZ@_7!waq#;vd+Yr>B$)cKCH0yK!!J``24~zfaQXI%7MONACZY F`~p2hYNP-F literal 0 HcmV?d00001 diff --git a/syft/pkg/cataloger/binary/testdata/classifiers/snippets/haskell-ghc/8.10.4/linux-amd64/ghc b/syft/pkg/cataloger/binary/testdata/classifiers/snippets/haskell-ghc/8.10.4/linux-amd64/ghc new file mode 100644 index 0000000000000000000000000000000000000000..b3e385f00ff1751eba6e39c0cd5713c7a7dd70b5 GIT binary patch literal 345 zcmZusJ8r}v5KYY~kX#!vFbv=mq~8iJD;~X8Ap>upE)u4Tx@fdZA1(nJ(rq2B~xPn=L>MGIT%1r z&4yB`F*ia;EZVa2Uzo>Oqbo5I8*iP7xoBGwCv$ZLWT@If(G6mb1U02lEe5o~kQTVL1yAumd(ptOSVdKeUFh3e>U>yqDZ7c%}pFUXUhk7a9p{C0rC S7n1$i3m?Y_id0nkzv2r_{$f-B literal 0 HcmV?d00001 diff --git a/syft/pkg/cataloger/binary/testdata/config.yaml b/syft/pkg/cataloger/binary/testdata/config.yaml index a161ed732..0100b8315 100644 --- a/syft/pkg/cataloger/binary/testdata/config.yaml +++ b/syft/pkg/cataloger/binary/testdata/config.yaml @@ -147,6 +147,23 @@ from-images: paths: - /usr/bin/deno + # haskell:7.10.3 detail information is missing. + - name: haskell-ghc + version: 7.10.3 + images: + - ref: haskell:7.10.3 + platform: linux/amd64 + paths: + - /opt/ghc/7.10.3/lib/ghc-7.10.3/bin/ghc + + - name: haskell-ghc + version: 8.10.4 + images: + - ref: haskell:8.10.4@sha256:30ecdaee0fd59cdcddf004a68c2d8995ba4212a64106abc3e411742c606e59ac + platform: linux/amd64 + paths: + - /opt/ghc/8.10.4/lib/ghc-8.10.4/bin/ghc + - name: haskell-ghc version: 9.6.5 images: @@ -155,6 +172,15 @@ from-images: paths: - /opt/ghc/9.6.5/lib/ghc-9.6.5/bin/ghc-9.6.5 + # haskell:7.10.3 detail information is missing. + - name: haskell-cabal + version: 1.22.6.0 + images: + - ref: haskell:7.10.3 + platform: linux/amd64 + paths: + - /opt/cabal/1.22/bin/cabal + - name: haskell-cabal version: 3.10.3.0 images: