From 78ef2cf53b62c5bc87e6f5877c53343473e0195f Mon Sep 17 00:00:00 2001 From: Oleksandr Vodotiiets Date: Wed, 30 Apr 2025 21:50:12 +0300 Subject: [PATCH] fix: Improve detection of erlang binary in alpine Linux (#3839) Signed-off-by: Oleksandr Vodotiiets Signed-off-by: Oleksandr Vodotiiets <61548316+avodotiiets@users.noreply.github.com> --- .../cataloger/binary/classifier_cataloger_test.go | 11 +++++++++++ syft/pkg/cataloger/binary/classifiers.go | 4 ++++ .../snippets/erlang/26.1.2/linux-arm64/beam.smp | Bin 0 -> 352 bytes .../cataloger/binary/test-fixtures/config.yaml | 8 ++++++++ 4 files changed, 23 insertions(+) create mode 100644 syft/pkg/cataloger/binary/test-fixtures/classifiers/snippets/erlang/26.1.2/linux-arm64/beam.smp diff --git a/syft/pkg/cataloger/binary/classifier_cataloger_test.go b/syft/pkg/cataloger/binary/classifier_cataloger_test.go index 341c7da7a..23dbd8b26 100644 --- a/syft/pkg/cataloger/binary/classifier_cataloger_test.go +++ b/syft/pkg/cataloger/binary/classifier_cataloger_test.go @@ -1067,6 +1067,17 @@ func Test_Cataloger_PositiveCases(t *testing.T) { Metadata: metadata("erlang-alpine-binary"), }, }, + { + logicalFixture: "erlang/26.1.2/linux-arm64", + expected: pkg.Package{ + Name: "erlang", + Version: "26.1.2", + Type: "binary", + PURL: "pkg:generic/erlang@26.1.2", + Locations: locations("beam.smp"), + Metadata: metadata("erlang-alpine-binary"), + }, + }, { logicalFixture: "swipl/9.3.8/linux-amd64", expected: pkg.Package{ diff --git a/syft/pkg/cataloger/binary/classifiers.go b/syft/pkg/cataloger/binary/classifiers.go index 1dabf7a5a..6f1d2c5a5 100644 --- a/syft/pkg/cataloger/binary/classifiers.go +++ b/syft/pkg/cataloger/binary/classifiers.go @@ -426,6 +426,10 @@ func DefaultClassifiers() []Classifier { // [NUL]/usr/local/src/otp-25.3.2.7/erts/ `(?m)/usr/local/src/otp-(?P[0-9]+\.[0-9]+(\.[0-9]+){0,2}(-rc[0-9])?)/erts/`, ), + FileContentsVersionMatcher( + // [NUL][NUL]26.1.2[NUL][NUL][NUL][NUL][NUL][NUL][NUL]NUL[NUL][NUL]Erlang/OTP + `\x00+(?P[0-9]+\.[0-9]+(\.[0-9]+){0,2}(-rc[0-9])?)\x00+Erlang/OTP`, + ), ), Package: "erlang", PURL: mustPURL("pkg:generic/erlang@version"), diff --git a/syft/pkg/cataloger/binary/test-fixtures/classifiers/snippets/erlang/26.1.2/linux-arm64/beam.smp b/syft/pkg/cataloger/binary/test-fixtures/classifiers/snippets/erlang/26.1.2/linux-arm64/beam.smp new file mode 100644 index 0000000000000000000000000000000000000000..f49aa07ceb9f665d00fbbe269238a4e3ea4d7b39 GIT binary patch literal 352 zcmZvWOKSr$41|03uP}rhlURPP_ug|0?Je{mt>q-JFJgz%e_ywx lUu)TcZC~&qk7c=C2X2SAJG#^#Wm@|!@$GjtPUV4j?HiamUC00c 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 8cf217360..b55527b63 100644 --- a/syft/pkg/cataloger/binary/test-fixtures/config.yaml +++ b/syft/pkg/cataloger/binary/test-fixtures/config.yaml @@ -71,6 +71,14 @@ from-images: paths: - /usr/local/lib/erlang/erts-15.0/bin/beam.smp + - name: erlang + version: 26.1.2 + images: + - ref: hexpm/elixir:1.15.6-erlang-26.1.2-alpine-3.18.4@sha256:e84f6667f4e3d2fe00fcdb9d1c2cdd614733296c39b20b28b092743f1161bc11 + platform: linux/arm64 + paths: + - /usr/local/lib/erlang/erts-14.1.1/bin/beam.smp + - version: 9.3.8 images: - ref: swipl:9.3.8@sha256:6a15e6a03afe943228924a5502ba763e653ff28d9b3391e2b3e1fc3e991f37d4