From c687b7bfa54a0e52d72736e1b91bbeb47f43aad1 Mon Sep 17 00:00:00 2001 From: Alan Pope Date: Fri, 7 Mar 2025 14:56:37 +0000 Subject: [PATCH] fix: improve fluent-bit binary detection regex pattern (#3701) * fix: improve fluent-bit binary detection regex pattern This fixes issue #3133 by updating the regex pattern for fluent-bit binary detection to better handle ANSI escape sequences and multiple null bytes between the version string and "Fluent Bit" text. The change also makes the %s format specifier optional, supporting all variations in fluent-bit binary signatures. Signed-off-by: Alan Pope * test: add fluent-bit 1.7.0-dev-3 test fixture for issue #3133 Signed-off-by: Alan Pope --------- Signed-off-by: Alan Pope --- .../cataloger/binary/classifier_cataloger_test.go | 11 +++++++++++ syft/pkg/cataloger/binary/classifiers.go | 3 ++- .../fluent-bit/1.7.0-dev-3/linux-amd64/fluent-bit | Bin 0 -> 354 bytes .../cataloger/binary/test-fixtures/config.yaml | 7 +++++++ 4 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 syft/pkg/cataloger/binary/test-fixtures/classifiers/snippets/fluent-bit/1.7.0-dev-3/linux-amd64/fluent-bit diff --git a/syft/pkg/cataloger/binary/classifier_cataloger_test.go b/syft/pkg/cataloger/binary/classifier_cataloger_test.go index 45ff37652..2d6b7a4ea 100644 --- a/syft/pkg/cataloger/binary/classifier_cataloger_test.go +++ b/syft/pkg/cataloger/binary/classifier_cataloger_test.go @@ -1221,6 +1221,17 @@ func Test_Cataloger_PositiveCases(t *testing.T) { Metadata: metadata("fluent-bit-binary"), }, }, + { + logicalFixture: "fluent-bit/1.7.0-dev-3/linux-amd64", + expected: pkg.Package{ + Name: "fluent-bit", + Version: "1.7.0", + Type: "binary", + PURL: "pkg:github/fluent/fluent-bit@1.7.0", + Locations: locations("fluent-bit"), + Metadata: metadata("fluent-bit-binary"), + }, + }, { logicalFixture: "wp/2.9.0/linux-amd64", expected: pkg.Package{ diff --git a/syft/pkg/cataloger/binary/classifiers.go b/syft/pkg/cataloger/binary/classifiers.go index 9bb623731..f0fff7a85 100644 --- a/syft/pkg/cataloger/binary/classifiers.go +++ b/syft/pkg/cataloger/binary/classifiers.go @@ -572,7 +572,8 @@ func DefaultClassifiers() []Classifier { // [NUL]3.0.2[NUL]%sFluent Bit // [NUL]2.2.3[NUL]Fluent Bit // [NUL]2.2.1[NUL][NUL][NUL]Fluent Bit - `\x00(?P[0-9]+\.[0-9]+\.[0-9]+)\x00[^\d]*Fluent`, + // [NUL]1.7.0[NUL]\x1b[1m[NUL]%sFluent Bit (versions 1.7.0-dev-3 through 1.7.0-dev-9 and 1.7.0-rc4 through 1.7.0-rc8) + `\x00(?P[0-9]+\.[0-9]+\.[0-9]+)\x00(\x1b\[1m\x00|\x00\x00)?(%s)?Fluent`, ), Package: "fluent-bit", PURL: mustPURL("pkg:github/fluent/fluent-bit@version"), diff --git a/syft/pkg/cataloger/binary/test-fixtures/classifiers/snippets/fluent-bit/1.7.0-dev-3/linux-amd64/fluent-bit b/syft/pkg/cataloger/binary/test-fixtures/classifiers/snippets/fluent-bit/1.7.0-dev-3/linux-amd64/fluent-bit new file mode 100644 index 0000000000000000000000000000000000000000..b1d5270a701d7a3a0f2b5f569917bbae6d742f7e GIT binary patch literal 354 zcmXw#No&I}6oh@&U&uue3{9bl^t3$5mq1IGT#`0vPB~dyV{q(%)t3JIhAg*X24;q@ zs}HfFsr`;!esE1DeM&>j6_pA(7nZcK`^x)@a$scWn&UC%&AtYuE2_Y7UVCsR1q&R# zWJU@N8YBpXLAzvh?IlX4t+p1>O2e!NuN)fYNNU=6D?=l_bow-d$!pIbC@qbGBp5Ql z$bAYzqewwTZIPo0uI7L)MU9XgA>;9wy1yLh^(M_dO?}(;zw{K5;(5JZtt(m%^sWq( zVm_Z2e2P<6jCTA`l*7vz0)1>U{V9iXAm?DTv*J+P(|yjzp_ZTo()o>t3$Vv=A+ literal 0 HcmV?d00001 diff --git a/syft/pkg/cataloger/binary/test-fixtures/config.yaml b/syft/pkg/cataloger/binary/test-fixtures/config.yaml index 1b0723314..f421cdfd3 100644 --- a/syft/pkg/cataloger/binary/test-fixtures/config.yaml +++ b/syft/pkg/cataloger/binary/test-fixtures/config.yaml @@ -688,6 +688,13 @@ from-images: paths: - /fluent-bit/bin/fluent-bit + - version: 1.7.0-dev-3 + images: + - ref: fluent/fluent-bit:1.7.0-dev-3@sha256:d8105ebefa27ca7d8ad2233ab0a4364ff43a9b31c484bde27f0d3d18988b34a0 + platform: linux/amd64 + paths: + - /fluent-bit/bin/fluent-bit + - name: openssl version: 1.1.1w images: