From 7fc3e8152439ba90114c2d46a1ca7af9161e91bb Mon Sep 17 00:00:00 2001 From: phatlc Date: Wed, 29 Jul 2026 01:52:32 +0700 Subject: [PATCH] fix(binary): match istio snapshot and older pre-release versions The istio pilot-agent/pilot-discovery classifiers missed every -snapshot.N build and the older -alpha.N/-beta.N/-rc.N layouts. Two defects: 1. The doubled-version matcher anchored on a bare x.y.z followed by NULs, but pre-release builds repeat the full version including the suffix (1.15.0-beta.0 NUL NUL NUL 1.15.0-beta.0), so the anchor never matched. Only the capture group had been widened previously. 2. -snapshot.N was absent from every alternation, and snapshot builds store the version only once with no leading copy, so no existing matcher could reach it. Widen the leading anchor to accept the same optional pre-release suffix it already accepts in the capture group, add -snapshot.N to each alternation, and add a matcher for the standalone snapshot layout. The new matcher is second so it can never shadow a normal build. Adds real captured snippets for pilot-agent and pilot-discovery at 1.0.0-snapshot.0, 1.5.0-alpha.0, 1.15.0-beta.0 and 1.19.0-rc.0. Fixes #5060 Signed-off-by: phatlc --- .../binary/classifier_cataloger_test.go | 88 ++++++++++++++++++ syft/pkg/cataloger/binary/classifiers.go | 18 ++-- .../1.0.0-snapshot.0/linux-amd64/pilot-agent | Bin 0 -> 356 bytes .../1.15.0-beta.0/linux-amd64/pilot-agent | Bin 0 -> 356 bytes .../1.19.0-rc.0/linux-amd64/pilot-agent | Bin 0 -> 356 bytes .../1.5.0-alpha.0/linux-amd64/pilot-agent | Bin 0 -> 356 bytes .../linux-amd64/pilot-discovery | Bin 0 -> 360 bytes .../1.15.0-beta.0/linux-amd64/pilot-discovery | Bin 0 -> 360 bytes .../1.19.0-rc.0/linux-amd64/pilot-discovery | Bin 0 -> 360 bytes .../1.5.0-alpha.0/linux-amd64/pilot-discovery | Bin 0 -> 360 bytes .../pkg/cataloger/binary/testdata/config.yaml | 64 +++++++++++++ 11 files changed, 164 insertions(+), 6 deletions(-) create mode 100644 syft/pkg/cataloger/binary/testdata/classifiers/snippets/istio_pilot-agent/1.0.0-snapshot.0/linux-amd64/pilot-agent create mode 100644 syft/pkg/cataloger/binary/testdata/classifiers/snippets/istio_pilot-agent/1.15.0-beta.0/linux-amd64/pilot-agent create mode 100644 syft/pkg/cataloger/binary/testdata/classifiers/snippets/istio_pilot-agent/1.19.0-rc.0/linux-amd64/pilot-agent create mode 100644 syft/pkg/cataloger/binary/testdata/classifiers/snippets/istio_pilot-agent/1.5.0-alpha.0/linux-amd64/pilot-agent create mode 100644 syft/pkg/cataloger/binary/testdata/classifiers/snippets/istio_pilot-discovery/1.0.0-snapshot.0/linux-amd64/pilot-discovery create mode 100644 syft/pkg/cataloger/binary/testdata/classifiers/snippets/istio_pilot-discovery/1.15.0-beta.0/linux-amd64/pilot-discovery create mode 100644 syft/pkg/cataloger/binary/testdata/classifiers/snippets/istio_pilot-discovery/1.19.0-rc.0/linux-amd64/pilot-discovery create mode 100644 syft/pkg/cataloger/binary/testdata/classifiers/snippets/istio_pilot-discovery/1.5.0-alpha.0/linux-amd64/pilot-discovery diff --git a/syft/pkg/cataloger/binary/classifier_cataloger_test.go b/syft/pkg/cataloger/binary/classifier_cataloger_test.go index 4cbd2f6f393..ac5d0555553 100644 --- a/syft/pkg/cataloger/binary/classifier_cataloger_test.go +++ b/syft/pkg/cataloger/binary/classifier_cataloger_test.go @@ -2151,6 +2151,28 @@ func Test_Cataloger_PositiveCases(t *testing.T) { Metadata: metadata("istio-binary"), }, }, + { + logicalFixture: "istio_pilot-discovery/1.19.0-rc.0/linux-amd64", + expected: pkg.Package{ + Name: "pilot-discovery", + Version: "1.19.0-rc.0", + Type: "binary", + PURL: "pkg:generic/istio@1.19.0-rc.0", + Locations: locations("pilot-discovery"), + Metadata: metadata("istio-binary"), + }, + }, + { + logicalFixture: "istio_pilot-discovery/1.15.0-beta.0/linux-amd64", + expected: pkg.Package{ + Name: "pilot-discovery", + Version: "1.15.0-beta.0", + Type: "binary", + PURL: "pkg:generic/istio@1.15.0-beta.0", + Locations: locations("pilot-discovery"), + Metadata: metadata("istio-binary"), + }, + }, { logicalFixture: "istio_pilot-discovery/1.10-dev/linux-amd64", expected: pkg.Package{ @@ -2173,6 +2195,17 @@ func Test_Cataloger_PositiveCases(t *testing.T) { Metadata: metadata("istio-binary"), }, }, + { + logicalFixture: "istio_pilot-discovery/1.5.0-alpha.0/linux-amd64", + expected: pkg.Package{ + Name: "pilot-discovery", + Version: "1.5.0-alpha.0", + Type: "binary", + PURL: "pkg:generic/istio@1.5.0-alpha.0", + Locations: locations("pilot-discovery"), + Metadata: metadata("istio-binary"), + }, + }, { logicalFixture: "istio_pilot-discovery/1.3.8/linux-amd64", expected: pkg.Package{ @@ -2195,6 +2228,17 @@ func Test_Cataloger_PositiveCases(t *testing.T) { Metadata: metadata("istio-binary"), }, }, + { + logicalFixture: "istio_pilot-discovery/1.0.0-snapshot.0/linux-amd64", + expected: pkg.Package{ + Name: "pilot-discovery", + Version: "1.0.0-snapshot.0", + Type: "binary", + PURL: "pkg:generic/istio@1.0.0-snapshot.0", + Locations: locations("pilot-discovery"), + Metadata: metadata("istio-binary"), + }, + }, { logicalFixture: "istio_pilot-agent/1.29.0-alpha.0/linux-amd64", expected: pkg.Package{ @@ -2239,6 +2283,28 @@ func Test_Cataloger_PositiveCases(t *testing.T) { Metadata: metadata("istio-binary"), }, }, + { + logicalFixture: "istio_pilot-agent/1.19.0-rc.0/linux-amd64", + expected: pkg.Package{ + Name: "pilot-agent", + Version: "1.19.0-rc.0", + Type: "binary", + PURL: "pkg:generic/istio@1.19.0-rc.0", + Locations: locations("pilot-agent"), + Metadata: metadata("istio-binary"), + }, + }, + { + logicalFixture: "istio_pilot-agent/1.15.0-beta.0/linux-amd64", + expected: pkg.Package{ + Name: "pilot-agent", + Version: "1.15.0-beta.0", + Type: "binary", + PURL: "pkg:generic/istio@1.15.0-beta.0", + Locations: locations("pilot-agent"), + Metadata: metadata("istio-binary"), + }, + }, { logicalFixture: "istio_pilot-agent/1.10-dev/linux-amd64", expected: pkg.Package{ @@ -2261,6 +2327,17 @@ func Test_Cataloger_PositiveCases(t *testing.T) { Metadata: metadata("istio-binary"), }, }, + { + logicalFixture: "istio_pilot-agent/1.5.0-alpha.0/linux-amd64", + expected: pkg.Package{ + Name: "pilot-agent", + Version: "1.5.0-alpha.0", + Type: "binary", + PURL: "pkg:generic/istio@1.5.0-alpha.0", + Locations: locations("pilot-agent"), + Metadata: metadata("istio-binary"), + }, + }, { logicalFixture: "istio_pilot-agent/1.1.17/linux-amd64", expected: pkg.Package{ @@ -2272,6 +2349,17 @@ func Test_Cataloger_PositiveCases(t *testing.T) { Metadata: metadata("istio-binary"), }, }, + { + logicalFixture: "istio_pilot-agent/1.0.0-snapshot.0/linux-amd64", + expected: pkg.Package{ + Name: "pilot-agent", + Version: "1.0.0-snapshot.0", + Type: "binary", + PURL: "pkg:generic/istio@1.0.0-snapshot.0", + Locations: locations("pilot-agent"), + Metadata: metadata("istio-binary"), + }, + }, { logicalFixture: "grafana/12.4.0-22081664032/linux-amd64", expected: pkg.Package{ diff --git a/syft/pkg/cataloger/binary/classifiers.go b/syft/pkg/cataloger/binary/classifiers.go index afd4c7536cb..7733869629e 100644 --- a/syft/pkg/cataloger/binary/classifiers.go +++ b/syft/pkg/cataloger/binary/classifiers.go @@ -1014,13 +1014,16 @@ func DefaultClassifiers() []binutils.Classifier { EvidenceMatcher: binutils.MatchAny( // [NUL]1.26.8[NUL][NUL]1.26.8[NUL] // [NUL]1.3.7[NUL][NUL][NUL]1.3.8[NUL] - m.FileContentsVersionMatcher(`[0-9]+\.[0-9]+\.[0-9]+\x00+(?P[0-9]+\.[0-9]+\.[0-9]+(-alpha\.[0-9]+|-beta\.[0-9]+|-rc\.[0-9]+|-dev)?)\x00+`), + // [NUL]1.15.0-beta.0[NUL][NUL][NUL]1.15.0-beta.0[NUL] (pre-release builds repeat the full version, suffix included) + m.FileContentsVersionMatcher(`[0-9]+\.[0-9]+\.[0-9]+(-alpha\.[0-9]+|-beta\.[0-9]+|-rc\.[0-9]+|-snapshot\.[0-9]+|-dev)?\x00+(?P[0-9]+\.[0-9]+\.[0-9]+(-alpha\.[0-9]+|-beta\.[0-9]+|-rc\.[0-9]+|-snapshot\.[0-9]+|-dev)?)\x00+`), + // [NUL][NUL][NUL]1.0.0-snapshot.0[NUL][NUL][NUL] (snapshot builds record the version only once) + m.FileContentsVersionMatcher(`\x00+(?P[0-9]+\.[0-9]+\.[0-9]+-snapshot\.[0-9]+)\x00+`), // Clean[NUL][NUL][NUL]1.8.0[NUL] - m.FileContentsVersionMatcher(`Clean\x00+(?P[0-9]+\.[0-9]+\.[0-9]+(-alpha\.[0-9]+|-beta\.[0-9]+|-rc\.[0-9]+|-dev)?)\x00+`), + m.FileContentsVersionMatcher(`Clean\x00+(?P[0-9]+\.[0-9]+\.[0-9]+(-alpha\.[0-9]+|-beta\.[0-9]+|-rc\.[0-9]+|-snapshot\.[0-9]+|-dev)?)\x00+`), // Modified[NUL][NUL][NUL][NUL][NUL][NUL][NUL][NUL]1.10-dev[NUL][NUL][NUL] m.FileContentsVersionMatcher(`Modified\x00+(?P[0-9]+\.[0-9]+-dev)\x00+`), // 1.1.17[NUL]...S=v[0-9]+\.[0-9]+\.[0-9]+(-alpha\.[0-9]+|-beta\.[0-9]+|-rc\.[0-9]+|-dev)?)\x00+.{1,100}S?=v[0-9]+\.[0-9]+\.[0-9]+(-alpha\.[0-9]+|-beta\.[0-9]+|-rc\.[0-9]+|-snapshot\.[0-9]+|-dev)?)\x00+.{1,100}S?=v[0-9]+\.[0-9]+\.[0-9]+(-alpha\.[0-9]+|-beta\.[0-9]+|-rc\.[0-9]+|-dev)?)\x00+`), + // [NUL]1.15.0-beta.0[NUL][NUL][NUL]1.15.0-beta.0[NUL] (pre-release builds repeat the full version, suffix included) + m.FileContentsVersionMatcher(`[0-9]+\.[0-9]+\.[0-9]+(-alpha\.[0-9]+|-beta\.[0-9]+|-rc\.[0-9]+|-snapshot\.[0-9]+|-dev)?\x00+(?P[0-9]+\.[0-9]+\.[0-9]+(-alpha\.[0-9]+|-beta\.[0-9]+|-rc\.[0-9]+|-snapshot\.[0-9]+|-dev)?)\x00+`), + // [NUL][NUL][NUL]1.0.0-snapshot.0[NUL][NUL][NUL] (snapshot builds record the version only once) + m.FileContentsVersionMatcher(`\x00+(?P[0-9]+\.[0-9]+\.[0-9]+-snapshot\.[0-9]+)\x00+`), // Clean[NUL][NUL][NUL]1.8.0[NUL] - m.FileContentsVersionMatcher(`Clean\x00+(?P[0-9]+\.[0-9]+\.[0-9]+(-alpha\.[0-9]+|-beta\.[0-9]+|-rc\.[0-9]+|-dev)?)\x00+`), + m.FileContentsVersionMatcher(`Clean\x00+(?P[0-9]+\.[0-9]+\.[0-9]+(-alpha\.[0-9]+|-beta\.[0-9]+|-rc\.[0-9]+|-snapshot\.[0-9]+|-dev)?)\x00+`), // Modified[NUL][NUL][NUL][NUL][NUL][NUL][NUL][NUL]1.10-dev[NUL][NUL][NUL] m.FileContentsVersionMatcher(`Modified\x00+(?P[0-9]+\.[0-9]+-dev)\x00+`), // 1.1.17[NUL]...S=v[0-9]+\.[0-9]+\.[0-9]+(-alpha\.[0-9]+|-beta\.[0-9]+|-rc\.[0-9]+|-dev)?)\x00+.{1,100}S?=v[0-9]+\.[0-9]+\.[0-9]+(-alpha\.[0-9]+|-beta\.[0-9]+|-rc\.[0-9]+|-snapshot\.[0-9]+|-dev)?)\x00+.{1,100}S?=vd(aX+?riW0; zxrDixCCqUyO6@=2-`(C^v#ZOC^Rv^F>7;u2`JC)l`ObUjP6A literal 0 HcmV?d00001 diff --git a/syft/pkg/cataloger/binary/testdata/classifiers/snippets/istio_pilot-agent/1.19.0-rc.0/linux-amd64/pilot-agent b/syft/pkg/cataloger/binary/testdata/classifiers/snippets/istio_pilot-agent/1.19.0-rc.0/linux-amd64/pilot-agent new file mode 100644 index 0000000000000000000000000000000000000000..581c08576dc217aecf7a4de950c38fc97e0b3f0d GIT binary patch literal 356 zcmZvWO-{rx423)V6aH50Bh3=c$WEQ4sl<*Ozy;F8nW8EtS;{ts&8Izsl=cq5`q$+i~Q4zxGO-S{emZ zvE#;4h?R25HC}^mFa#j3Af}jf05r)fv?W?jRdm`?sZ{a=BDEdw!cf~vvGW>^@ z`nJ2pEfobW(Jf)|6qfKWe~VMQy1Y0)6Q?J~M~4Udd$VG;Gk)gVA1*#_?jE+<>-FdR E7d7osLI3~& literal 0 HcmV?d00001 diff --git a/syft/pkg/cataloger/binary/testdata/classifiers/snippets/istio_pilot-agent/1.5.0-alpha.0/linux-amd64/pilot-agent b/syft/pkg/cataloger/binary/testdata/classifiers/snippets/istio_pilot-agent/1.5.0-alpha.0/linux-amd64/pilot-agent new file mode 100644 index 0000000000000000000000000000000000000000..8c6b56662d284f3357d5da7d719033e340dd198f GIT binary patch literal 356 zcmZ8b%WlLV42*g!w^scCq?|Y64apz$+%GU-Hj!wEv`AI|zHYm#t!j-8o*9gHc*lhw zTW$RWXWTn$rChKtTzRLhFosp!&wX9ERDxah?KrT%t)Q%1c#_UVThN(QWQY;WY+_Ev z<`Pp#Qd$+VPAVh;2$@O@5>qZjd9;C*t>SGMxY^CBBt5Hu=!6SJx~P2uPm~szjg)|y zz9Xy8$$KZutkIBYjAd*bM;<>r^6Q$sH(pw;?SqrV28svDm+#9pqxE8*iKyP8lSz?eNdcOJO}at%5Q} z1#l5DmcK?Yp$mrME>*3ZkR@5v+G`mUw-FhZ9SEtaiuyxF`WutxL}Ti@^hV2xOiF!x zzE4m6_5`Ka1~#xBdpC^xlsE9ho)IWqFE8(pyW`htwpdK&H|N`Ff;Fs`SC7Zt6ffqp Mc@f(gz#< z#czGK?B6T@#$C&jdKdQ3J{_XGjM<&J%F*k3Ju{b>Jq7GEIVhBL~J|$J7x(KYh{`k z$wnmaD~HCj%_-VJX)K1OLT8BCQ8bovVpNu_HZd3wVmuy8+9sCAH)ZN&?7Oc2lzAkI zte2f-4G*O#rzK3)ggE)B%Dw-5cYAYvB`z<{&rVN9!$I-IkE7kH+*#Jo_k7O}2P_tY Mr#-`w@1N(RUljRL;s5{u literal 0 HcmV?d00001 diff --git a/syft/pkg/cataloger/binary/testdata/classifiers/snippets/istio_pilot-discovery/1.19.0-rc.0/linux-amd64/pilot-discovery b/syft/pkg/cataloger/binary/testdata/classifiers/snippets/istio_pilot-discovery/1.19.0-rc.0/linux-amd64/pilot-discovery new file mode 100644 index 0000000000000000000000000000000000000000..4ee78a5e385e4e7652e1aa3f442df57c83788ace GIT binary patch literal 360 zcmZvWOHRW;5JVmR48Ilok+MXIy65Y$#Eu)l1!mek#FDYC!~*3a9Eb%c;0PRq1jq)_ zi)y_psZ?Ej;z|xp+mExlSyBJY%eClpUh!B-iyFXrCtB_v$3-Pkfmn6TFz|T4h|0Q3 zIt8ZWz{wk`OBHfR(Sl7#1cpnfbDb>#x*QdHjh=H^2kVViDn|n%H!bhVjOS4M=(9o< zbBTsHBN?3lSnFhyMFJODlY`(bCD0+Uqgs=)0ksg*=~Slm$ntll9DAAjw(Vc!CKAQw zhS)XKHSH~KsVH!cVGgq;&Ea4EHaBv0d2xOwPEU@H4iEPCCdFhI{QS2+TzuTzJ#4+# H>(BQuN6u5) literal 0 HcmV?d00001 diff --git a/syft/pkg/cataloger/binary/testdata/classifiers/snippets/istio_pilot-discovery/1.5.0-alpha.0/linux-amd64/pilot-discovery b/syft/pkg/cataloger/binary/testdata/classifiers/snippets/istio_pilot-discovery/1.5.0-alpha.0/linux-amd64/pilot-discovery new file mode 100644 index 0000000000000000000000000000000000000000..1b646522eefe87e416eddf1a8a91e0060a7db977 GIT binary patch literal 360 zcmZ8b+fKwF5N&*uH;o@a(&ue}0)_s8&wc^S47LfD#uCl`y{Nlc7_`?B zK^sgF97t)D!x5AN5h!3Y(MbYKjhe_fmex$yWtd!&##smx8es&Ok%Vipjb3Q9GGUA` zDK9{%V6BSn0w|okCp~IntnYgs&z1P)O