mirror of
https://github.com/anchore/syft.git
synced 2026-11-26 13:44:11 +01:00
Compare commits
+1
-1
@@ -24,7 +24,7 @@ tools:
|
||||
# used to parse JSON/YAML annotations on the fixture cache image
|
||||
- name: yq
|
||||
version:
|
||||
want: v4.54.1
|
||||
want: v4.54.3
|
||||
method: github-release
|
||||
with:
|
||||
repo: mikefarah/yq
|
||||
|
||||
@@ -89,13 +89,13 @@ jobs:
|
||||
uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4.4.1
|
||||
|
||||
- name: Login to Docker Hub
|
||||
uses: docker/login-action@81c6f93d4bc991e510b342a00b419b3bb4efc5c6 #v4.7.0
|
||||
uses: docker/login-action@8aa5831fb8d48d8f76594c7ddde61ae58019f550 #v4.8.0
|
||||
with:
|
||||
username: ${{ secrets.ANCHOREOSSWRITE_DH_USERNAME }}
|
||||
password: ${{ secrets.ANCHOREOSSWRITE_DH_PAT }}
|
||||
|
||||
- name: Login to GitHub Container Registry
|
||||
uses: docker/login-action@81c6f93d4bc991e510b342a00b419b3bb4efc5c6 #v4.7.0
|
||||
uses: docker/login-action@8aa5831fb8d48d8f76594c7ddde61ae58019f550 #v4.8.0
|
||||
with:
|
||||
registry: ghcr.io
|
||||
username: ${{ github.actor }}
|
||||
|
||||
@@ -25,7 +25,7 @@ jobs:
|
||||
persist-credentials: false
|
||||
|
||||
- name: "Run zizmor"
|
||||
uses: zizmorcore/zizmor-action@53290badfa369cb0bf7ad16342cb62c2fa47ac7b # v0.8.0
|
||||
uses: zizmorcore/zizmor-action@45d7276c9ca790aabd705e31ca99c6185c3e76dd # v0.8.1
|
||||
with:
|
||||
# there is a pass/fail gate as a repo ruleset (if there is no ruleset configured then the action will pass by default)
|
||||
advanced-security: true
|
||||
|
||||
@@ -284,7 +284,7 @@ jobs:
|
||||
contents: read
|
||||
steps:
|
||||
- name: Install Cosign
|
||||
uses: sigstore/cosign-installer@6f9f17788090df1f26f669e9d70d6ae9567deba6 # v4.1.2
|
||||
uses: sigstore/cosign-installer@756fe2d284c7292c4e9b62c8a28f1e5629c59532 # v4.1.3
|
||||
|
||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 #v7.0.1
|
||||
with:
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
package integration
|
||||
|
||||
import (
|
||||
"sort"
|
||||
"testing"
|
||||
|
||||
"github.com/scylladb/go-set/strset"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/anchore/syft/syft/artifact"
|
||||
"github.com/anchore/syft/syft/pkg"
|
||||
"github.com/anchore/syft/syft/source"
|
||||
)
|
||||
|
||||
func TestDpkgStatusAndStatusDir(t *testing.T) {
|
||||
// the fixture image lists gzip in both /var/lib/dpkg/status and /var/lib/dpkg/status.d/gzip, bzip2 only in
|
||||
// status.d, and libc6 only in status. The status file is written by two layers. A package described
|
||||
// by both files must be reported once, whichever layers are cataloged.
|
||||
expected := []string{
|
||||
"bzip2@1.0.8-6+dhi2",
|
||||
"gzip@1.13-1+dhi1",
|
||||
"libc6@2.41-12+deb13u3+dhi1",
|
||||
}
|
||||
|
||||
for _, scope := range []source.Scope{source.SquashedScope, source.AllLayersScope, source.DeepSquashedScope} {
|
||||
t.Run(string(scope), func(t *testing.T) {
|
||||
sbom, _ := catalogFixtureImage(t, "image-dpkg-status-and-status-d", scope)
|
||||
|
||||
var got []string
|
||||
for _, p := range sbom.Artifacts.Packages.Sorted(pkg.DebPkg) {
|
||||
got = append(got, p.Name+"@"+p.Version)
|
||||
}
|
||||
sort.Strings(got)
|
||||
|
||||
assert.Equal(t, expected, got)
|
||||
|
||||
// gzip keeps status as its only primary evidence, with status.d supporting it
|
||||
gzip := sbom.Artifacts.Packages.PackagesByName("gzip")
|
||||
require.Len(t, gzip, 1)
|
||||
assert.Equal(t, []string{"/var/lib/dpkg/status"}, evidencePaths(gzip[0], pkg.PrimaryEvidenceAnnotation))
|
||||
assert.Equal(t, []string{"/var/lib/dpkg/status.d/gzip"}, evidencePaths(gzip[0], pkg.SupportingEvidenceAnnotation))
|
||||
|
||||
// and the dependency on libc6 points at the package that was reported, not a copy from before the merge
|
||||
var dependents []artifact.ID
|
||||
for _, r := range sbom.Relationships {
|
||||
from, ok := r.From.(pkg.Package)
|
||||
if r.Type != artifact.DependencyOfRelationship || !ok || from.Name != "libc6" {
|
||||
continue
|
||||
}
|
||||
dependents = append(dependents, r.To.ID())
|
||||
}
|
||||
assert.Contains(t, dependents, gzip[0].ID())
|
||||
for _, id := range dependents {
|
||||
assert.NotNil(t, sbom.Artifacts.Packages.Package(id), "libc6 is a dependency of a package that is not in the SBOM")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// evidencePaths returns the distinct location paths of a package carrying the given evidence annotation.
|
||||
func evidencePaths(p pkg.Package, evidence string) []string {
|
||||
paths := strset.New()
|
||||
for _, l := range p.Locations.ToSlice() {
|
||||
if l.Annotations[pkg.EvidenceAnnotationKey] == evidence {
|
||||
paths.Add(l.RealPath)
|
||||
}
|
||||
}
|
||||
list := paths.List()
|
||||
sort.Strings(list)
|
||||
return list
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
# verbatim dpkg records from a Docker Hardened Images Debian 13 image, which lists installed packages in both
|
||||
# /var/lib/dpkg/status.d/<name> and /var/lib/dpkg/status. The status file is written by two layers (the second adds
|
||||
# libc6) so that it is seen more than once when every layer is cataloged.
|
||||
FROM scratch
|
||||
COPY packages/ /
|
||||
COPY status-base/ /
|
||||
COPY status-updated/ /
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
Package: bzip2
|
||||
Version: 1.0.8-6+dhi2
|
||||
Architecture: arm64
|
||||
Maintainer: Docker Hardened Images <dhi@docker.com>
|
||||
Installed-Size: 193
|
||||
Depends: libbz2-1.0 (= 1.0.8-6+dhi2), libc6 (>= 2.41)
|
||||
Suggests: bzip2-doc
|
||||
Replaces: libbz2 (<< 0.9.5d-3)
|
||||
Section: utils
|
||||
Priority: standard
|
||||
Multi-Arch: foreign
|
||||
Homepage: https://sourceware.org/bzip2/
|
||||
Description: high-quality block-sorting file compressor - utilities
|
||||
bzip2 is a freely available, patent free, data compressor.
|
||||
.
|
||||
bzip2 compresses files using the Burrows-Wheeler block-sorting text
|
||||
compression algorithm, and Huffman coding. Compression is generally
|
||||
considerably better than that achieved by more conventional
|
||||
LZ77/LZ78-based compressors, and approaches the performance of the PPM
|
||||
family of statistical compressors.
|
||||
.
|
||||
The archive file format of bzip2 (.bz2) is incompatible with that of its
|
||||
predecessor, bzip (.bz).
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
Package: gzip
|
||||
Version: 1.13-1+dhi1
|
||||
Architecture: arm64
|
||||
Essential: yes
|
||||
Maintainer: Docker Hardened Images <dhi@docker.com>
|
||||
Installed-Size: 287
|
||||
Pre-Depends: libc6 (>= 2.41)
|
||||
Suggests: less
|
||||
Conflicts: zutils (<< 1.13-2~)
|
||||
Section: utils
|
||||
Priority: required
|
||||
Homepage: https://www.gnu.org/software/gzip/
|
||||
Description: GNU compression utilities
|
||||
This package provides the standard GNU file compression utilities, which
|
||||
are also the default compression tools for Debian. They typically operate
|
||||
on files with names ending in '.gz', but can also decompress files ending
|
||||
in '.Z' created with 'compress'.
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
Package: gzip
|
||||
Status: install ok installed
|
||||
Version: 1.13-1+dhi1
|
||||
Architecture: arm64
|
||||
Essential: yes
|
||||
Maintainer: Docker Hardened Images <dhi@docker.com>
|
||||
Installed-Size: 287
|
||||
Pre-Depends: libc6 (>= 2.41)
|
||||
Suggests: less
|
||||
Conflicts: zutils (<< 1.13-2~)
|
||||
Section: utils
|
||||
Priority: required
|
||||
Homepage: https://www.gnu.org/software/gzip/
|
||||
Description: GNU compression utilities
|
||||
This package provides the standard GNU file compression utilities, which
|
||||
are also the default compression tools for Debian. They typically operate
|
||||
on files with names ending in '.gz', but can also decompress files ending
|
||||
in '.Z' created with 'compress'.
|
||||
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
Package: gzip
|
||||
Status: install ok installed
|
||||
Version: 1.13-1+dhi1
|
||||
Architecture: arm64
|
||||
Essential: yes
|
||||
Maintainer: Docker Hardened Images <dhi@docker.com>
|
||||
Installed-Size: 287
|
||||
Pre-Depends: libc6 (>= 2.41)
|
||||
Suggests: less
|
||||
Conflicts: zutils (<< 1.13-2~)
|
||||
Section: utils
|
||||
Priority: required
|
||||
Homepage: https://www.gnu.org/software/gzip/
|
||||
Description: GNU compression utilities
|
||||
This package provides the standard GNU file compression utilities, which
|
||||
are also the default compression tools for Debian. They typically operate
|
||||
on files with names ending in '.gz', but can also decompress files ending
|
||||
in '.Z' created with 'compress'.
|
||||
|
||||
Package: libc6
|
||||
Status: install ok installed
|
||||
Source: glibc
|
||||
Version: 2.41-12+deb13u3+dhi1
|
||||
Architecture: arm64
|
||||
Maintainer: Docker Hardened Images <dhi@docker.com>
|
||||
Installed-Size: 23769
|
||||
Depends: libgcc-s1
|
||||
Recommends: libidn2-0 (>= 2.0.5~)
|
||||
Suggests: glibc-doc, debconf | debconf-2.0, libc-l10n, locales, libnss-nis, libnss-nisplus
|
||||
Breaks: base-files (<< 13.3~), chrony (<< 4.2-3~), dhcpcd (<< 1:10.1.0-7~), fakechroot (<< 2.19-3.5), firefox (<< 91~), firefox-esr (<< 91~), gnumach-image-1.8-486 (<< 2:1.8+git20210923~), gnumach-image-1.8-486-dbg (<< 2:1.8+git20210923~), gnumach-image-1.8-xen-486 (<< 2:1.8+git20210923~), gnumach-image-1.8-xen-486-dbg (<< 2:1.8+git20210923~), hurd (<< 1:0.9.git20220301-2), libamdhip64-5 (<< 5.7.1-5+b1), libhiprtc-builtins5 (<< 5.7.1-5+b1), librccl1 (<< 5.4.3-3+b1), libswupdate0.1 (<< 2024.12.1+dfsg-1+b3), locales (<< 2.41), locales-all (<< 2.41), lua-swupdate (<< 2024.12.1+dfsg-1+b3), nscd (<< 2.41), pd-scaf (<< 1:0.14.1+darcs20180201-6+b4), postgresql-15-pllua (<< 1:2.0.12-4), postgresql-17-pllua (<< 1:2.0.12-3+b2), python3-iptables (<< 1.0.0-2), python3-mrgingham (<< 1.25-1), python3-onnxruntime (<< 1.20.1+dfsg-2~), sysvinit (<< 3.09-2~), sysvinit-core (<< 3.09-2~), tinydns (<< 1:1.05-14), uwsgi-plugin-pypy3 (<< 0.0.2+b1), valgrind (<< 1:3.19.0-1~)
|
||||
Section: libs
|
||||
Priority: optional
|
||||
Multi-Arch: same
|
||||
Homepage: https://www.gnu.org/software/libc/libc.html
|
||||
Description: GNU C Library: Shared libraries
|
||||
Contains the standard libraries that are used by nearly all programs on
|
||||
the system. This package includes shared versions of the standard C library
|
||||
and the standard math library, as well as many others.
|
||||
|
||||
@@ -22,7 +22,7 @@ require (
|
||||
github.com/anchore/go-sync v0.1.2
|
||||
github.com/anchore/go-version v1.2.2-0.20200701162849-18adb9c92b9b
|
||||
github.com/anchore/packageurl-go v0.2.0
|
||||
github.com/anchore/stereoscope v0.4.1
|
||||
github.com/anchore/stereoscope v0.4.2
|
||||
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be
|
||||
github.com/aquasecurity/go-pep440-version v0.0.1
|
||||
github.com/bitnami/go-version v0.0.0-20250131085805-b1f57a8634ef
|
||||
@@ -100,7 +100,7 @@ require (
|
||||
golang.org/x/time v0.16.0
|
||||
golang.org/x/tools v0.52.0
|
||||
howett.net/plist v1.0.1
|
||||
modernc.org/sqlite v1.61.0
|
||||
modernc.org/sqlite v1.61.1
|
||||
)
|
||||
|
||||
require github.com/github/go-spdx/v2 v2.8.0
|
||||
@@ -186,7 +186,7 @@ require (
|
||||
github.com/containers/ocicrypt v1.3.2 // indirect
|
||||
github.com/cyberphone/json-canonicalization v0.0.0-20241213102144-19d51d7fe467 // indirect
|
||||
github.com/cyphar/filepath-securejoin v0.7.0 // indirect
|
||||
github.com/docker/cli v29.9.2+incompatible // indirect
|
||||
github.com/docker/cli v29.9.3+incompatible // indirect
|
||||
github.com/docker/docker-credential-helpers v0.9.10 // indirect
|
||||
github.com/docker/go-connections v0.8.2 // indirect
|
||||
github.com/docker/go-units v0.5.0 // indirect
|
||||
@@ -320,11 +320,12 @@ require (
|
||||
go.opentelemetry.io/contrib/detectors/gcp v1.44.0 // indirect
|
||||
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.71.0 // indirect
|
||||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.71.0 // indirect
|
||||
go.opentelemetry.io/otel v1.46.0 // indirect
|
||||
go.opentelemetry.io/otel/metric v1.46.0 // indirect
|
||||
go.opentelemetry.io/otel/sdk v1.46.0 // indirect
|
||||
go.opentelemetry.io/otel/sdk/metric v1.46.0 // indirect
|
||||
go.opentelemetry.io/otel/trace v1.46.0 // indirect
|
||||
go.opentelemetry.io/otel v1.47.0 // indirect
|
||||
go.opentelemetry.io/otel/log v1.47.0 // indirect
|
||||
go.opentelemetry.io/otel/metric v1.47.0 // indirect
|
||||
go.opentelemetry.io/otel/sdk v1.47.0 // indirect
|
||||
go.opentelemetry.io/otel/sdk/metric v1.47.0 // indirect
|
||||
go.opentelemetry.io/otel/trace v1.47.0 // indirect
|
||||
go.podman.io/image/v5 v5.42.0 // indirect
|
||||
go.podman.io/storage v1.65.0 // indirect
|
||||
go4.org v0.0.0-20230225012048-214862532bf5 // indirect
|
||||
|
||||
@@ -150,8 +150,8 @@ github.com/anchore/go-version v1.2.2-0.20200701162849-18adb9c92b9b h1:e1bmaoJfZV
|
||||
github.com/anchore/go-version v1.2.2-0.20200701162849-18adb9c92b9b/go.mod h1:Bkc+JYWjMCF8OyZ340IMSIi2Ebf3uwByOk6ho4wne1E=
|
||||
github.com/anchore/packageurl-go v0.2.0 h1:CkrM4RMUwrEGAiE1OVlxaZNzWj0TuHRey7o4T/EAErk=
|
||||
github.com/anchore/packageurl-go v0.2.0/go.mod h1:2JCgOQMIsqZ7TmliXG4PnUthPJAKE3mWQbsW2XHjAOE=
|
||||
github.com/anchore/stereoscope v0.4.1 h1:7mxw24JCabbJIAcyvQDjBd2pbzo+0HSFVgjYlE8Zm+k=
|
||||
github.com/anchore/stereoscope v0.4.1/go.mod h1:hYJsi3M8a8N1O66u+rMQSgv5TREGM7QIjKBjPPnwiD8=
|
||||
github.com/anchore/stereoscope v0.4.2 h1:tiLX01TpChU4+k1Jlv+uwF5lVdSCJVKuh8hQXl8iqQI=
|
||||
github.com/anchore/stereoscope v0.4.2/go.mod h1:Cru29+t2nps1BJxWzAEc4RN9RQI7AAizzoCVM9cheR0=
|
||||
github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883/go.mod h1:rCTlJbsFo29Kk6CurOXKm700vrz8f0KW0JNfpkRJY/8=
|
||||
github.com/andybalholm/brotli v1.2.8 h1:H9F6r7RNwzSRsx/lytpIYkbjNFMt2yNBwsJ2+0gpx78=
|
||||
github.com/andybalholm/brotli v1.2.8/go.mod h1:rzTDkvFWvIrjDXZHkuS16NPggd91W3kUSvPlQ1pLaKY=
|
||||
@@ -351,8 +351,8 @@ github.com/distribution/reference v0.6.0 h1:0IXCQ5g4/QMHHkarYzh5l+u8T3t73zM5Qvfr
|
||||
github.com/distribution/reference v0.6.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E=
|
||||
github.com/djherbis/times v1.6.0 h1:w2ctJ92J8fBvWPxugmXIv7Nz7Q3iDMKNx9v5ocVH20c=
|
||||
github.com/djherbis/times v1.6.0/go.mod h1:gOHeRAz2h+VJNZ5Gmc/o7iD9k4wW7NMVqieYCY99oc0=
|
||||
github.com/docker/cli v29.9.2+incompatible h1:trup/vUxx5uUo2t+87Cd9AmITR+DvKUe4H2tTtZN8FY=
|
||||
github.com/docker/cli v29.9.2+incompatible/go.mod h1:JLrzqnKDaYBop7H2jaqPtU4hHvMKP+vjCwu2uszcLI8=
|
||||
github.com/docker/cli v29.9.3+incompatible h1:SBaMp7ecohadEHMDrUJg22t9I3awqsAVhnJ7GOcWpfE=
|
||||
github.com/docker/cli v29.9.3+incompatible/go.mod h1:JLrzqnKDaYBop7H2jaqPtU4hHvMKP+vjCwu2uszcLI8=
|
||||
github.com/docker/distribution v2.8.3+incompatible h1:AtKxIZ36LoNK51+Z6RpzLpddBirtxJnzDrHLEKxTAYk=
|
||||
github.com/docker/distribution v2.8.3+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w=
|
||||
github.com/docker/docker-credential-helpers v0.9.10 h1:LCWwv7UmS7fQVmdKDWeMuureOeY5kkbC5kZfkzxkS6k=
|
||||
@@ -1057,20 +1057,22 @@ go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.7
|
||||
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.71.0/go.mod h1:dylvB+ZiiwMvsDij9O84Uy7SijLgHMX4mbkncds+4Sw=
|
||||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.71.0 h1:3g7B90UzBltIDKq1/5mrTGxTnOFDV0ICOhLoxiZ8jlg=
|
||||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.71.0/go.mod h1:Ef8SuTh59BT7+ofpDxN9z+yOlc4t2GjLmKDgYNJL/NU=
|
||||
go.opentelemetry.io/otel v1.46.0 h1:FHt5/CDyVxi/8IM1CH7VE/rRgq3kLHa2mSTVMO8AWyc=
|
||||
go.opentelemetry.io/otel v1.46.0/go.mod h1:Gj3SEScelsNC45tp4nSxRYlS+f5iez7W8XPMCt905kE=
|
||||
go.opentelemetry.io/otel v1.47.0 h1:j7ALJ/zgkS7Z6aeJW09p8VC9804bC+PpeTfCD4XPnOM=
|
||||
go.opentelemetry.io/otel v1.47.0/go.mod h1:8wS9O2qfXrYrzp6hIF/HOYJJf/wIhFPhR2xLuP+iXQU=
|
||||
go.opentelemetry.io/otel/exporters/stdout/stdoutmetric v1.44.0 h1:hqxVTu/GtBF+vJ8d1fzW7fRxZFvgoDjWcxwwCaFDYpU=
|
||||
go.opentelemetry.io/otel/exporters/stdout/stdoutmetric v1.44.0/go.mod h1:z5fVEF4X5v0ESvlJqBrrFlBVoj5EQuefZpzsu7R+x5Q=
|
||||
go.opentelemetry.io/otel/metric v1.46.0 h1:yBnkXvgV7AXFILZc5K6IZe/CBFF3OS7BJ8ov6/lj0K8=
|
||||
go.opentelemetry.io/otel/metric v1.46.0/go.mod h1:iPmdWqifKUdzziPkvvzIJXITl56fQx2mGM/DHLB3/2o=
|
||||
go.opentelemetry.io/otel/metric/x v0.68.0 h1:TA/cBT23D3MnxYPwHL7YFOdYGdx0A0v+s7Mzotpd1dU=
|
||||
go.opentelemetry.io/otel/metric/x v0.68.0/go.mod h1:agudOmvWhwUTjgibWDzxD2PoWYnpw5Ht5jISYOD2Hd4=
|
||||
go.opentelemetry.io/otel/sdk v1.46.0 h1:h5CNQQjEbuQXY/JfZtgt3i7HVFV3aHPO2OAwO2eTYPI=
|
||||
go.opentelemetry.io/otel/sdk v1.46.0/go.mod h1:GAERFXFt5SYCEB+YiKUbMBeza6UaDH7GmGOZEfh2gSM=
|
||||
go.opentelemetry.io/otel/sdk/metric v1.46.0 h1:0piZ26EG4RBfebb2jhDH6ERCYHoVWduc3kLgPCwSnSE=
|
||||
go.opentelemetry.io/otel/sdk/metric v1.46.0/go.mod h1:I1PbKrdVc8Qu8HYVDNtqVIwLwjNrhsV/uFuxfwg8mO4=
|
||||
go.opentelemetry.io/otel/trace v1.46.0 h1:OULy7ccdJnZtJ0UDYFOIGaCmiWzJ8Vi2G/Rsu60qs1c=
|
||||
go.opentelemetry.io/otel/trace v1.46.0/go.mod h1:J7GAXweO77XSFkB/rmAqk9D6ihszhFjLU+d9WuUxDLI=
|
||||
go.opentelemetry.io/otel/log v1.47.0 h1:cOTS1CcLbSQeZKanGJ+0JpF/+t4PELi3O3bbl2lqCcI=
|
||||
go.opentelemetry.io/otel/log v1.47.0/go.mod h1:9byitSQ5pLC6PpqwGXjqdMKya6ZTswHRZh2vvXT33nw=
|
||||
go.opentelemetry.io/otel/metric v1.47.0 h1:4PptaldXx3Eat1XjMZ68pPJEs5wrhlemctZE9a3UdWY=
|
||||
go.opentelemetry.io/otel/metric v1.47.0/go.mod h1:ADGSXxRrXM6bjbvLo535EstVFlPpPYZm4LBKixjDHwU=
|
||||
go.opentelemetry.io/otel/metric/x v0.69.0 h1:DjRLr15H83v+hCW7JA9NoJvOkYTtmq5YoDRbe9deYpM=
|
||||
go.opentelemetry.io/otel/metric/x v0.69.0/go.mod h1:uVvsMPMFFyj/HUQfrUnH3JjnOQ1dwFDorgFLRBasM0k=
|
||||
go.opentelemetry.io/otel/sdk v1.47.0 h1:zWXEr4j2lFefG87TU6Yg8a7ngfohIKFZHKp0Hf5hC6I=
|
||||
go.opentelemetry.io/otel/sdk v1.47.0/go.mod h1:VUc24kiOeoGsxG8G9ULx3fWKvB7jMhnGE8Oi607lgR0=
|
||||
go.opentelemetry.io/otel/sdk/metric v1.47.0 h1:lfISg2j93VT6yqdk9OfUaZmw/GfcZqCCV3jdXtsPnKw=
|
||||
go.opentelemetry.io/otel/sdk/metric v1.47.0/go.mod h1:ypLp+mW1Nt2x+Szt3b5/i1syodyts49lMOwxpDI3VGw=
|
||||
go.opentelemetry.io/otel/trace v1.47.0 h1:JOjX/Oci8K94QHddo+bbfya/Ai/nf6/dt9ZfrFNWSrM=
|
||||
go.opentelemetry.io/otel/trace v1.47.0/go.mod h1:jNaSLa2PZEYFG6fRjJABAu+bw4FS08uDmPg28lTghu0=
|
||||
go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI=
|
||||
go.podman.io/image/v5 v5.42.0 h1:C//Ix0Thj2LYOQO6++NjU3McLFLQbf4czgUyH98R9gc=
|
||||
go.podman.io/image/v5 v5.42.0/go.mod h1:mmIgf9EdpF68j8vdX1/OxhOSIknU1PO3G6/ClRkrwm4=
|
||||
@@ -1630,8 +1632,8 @@ modernc.org/opt v0.2.0 h1:tGyef5ApycA7FSEOMraay9SaTk5zmbx7Tu+cJs4QKZg=
|
||||
modernc.org/opt v0.2.0/go.mod h1:03fq9lsNfvkYSfxrfUhZCWPk1lm4cq4N+Bh//bEtgns=
|
||||
modernc.org/sortutil v1.2.1 h1:+xyoGf15mM3NMlPDnFqrteY07klSFxLElE2PVuWIJ7w=
|
||||
modernc.org/sortutil v1.2.1/go.mod h1:7ZI3a3REbai7gzCLcotuw9AC4VZVpYMjDzETGsSMqJE=
|
||||
modernc.org/sqlite v1.61.0 h1:sQi63oLQ9uquAUA4CzOisH35Q3pEszkPBuHM0tFL8CY=
|
||||
modernc.org/sqlite v1.61.0/go.mod h1:f4gr5tbpx2umklaT/QVtbi/50hNdM+4ng+2zMo8KXJ0=
|
||||
modernc.org/sqlite v1.61.1 h1:TBEE49wz7VlxS+qXRXMQiPUZYOXHJ4ku83daYv1fe04=
|
||||
modernc.org/sqlite v1.61.1/go.mod h1:f4gr5tbpx2umklaT/QVtbi/50hNdM+4ng+2zMo8KXJ0=
|
||||
modernc.org/strutil v1.2.1 h1:UneZBkQA+DX2Rp35KcM69cSsNES9ly8mQWD71HKlOA0=
|
||||
modernc.org/strutil v1.2.1/go.mod h1:EHkiggD70koQxjVdSBM3JKM7k6L0FbGE5eymy9i3B9A=
|
||||
modernc.org/token v1.1.0 h1:Xl7Ap9dKaEs5kLoOQeQmPWevfnk/DM5qcLcYlA8ys6Y=
|
||||
|
||||
@@ -14,8 +14,15 @@ import (
|
||||
|
||||
const (
|
||||
LicenseRefPrefix = "LicenseRef-" // prefix for non-standard licenses
|
||||
epl2LicenseID = "EPL-2.0"
|
||||
)
|
||||
|
||||
var licenseExpressionsByURL = map[string]string{
|
||||
"projects.eclipse.org/license/secondary-gpl-2.0-cp": "GPL-2.0-only WITH Classpath-exception-2.0",
|
||||
"www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt": epl2LicenseID,
|
||||
"www.gnu.org/software/classpath/license.html": "GPL-2.0-only WITH Classpath-exception-2.0",
|
||||
}
|
||||
|
||||
//go:generate go run ./generate
|
||||
|
||||
// ID returns the canonical license ID for the given license ID
|
||||
@@ -53,6 +60,11 @@ func LicenseByURL(url string) (LicenseInfo, bool) {
|
||||
ID: id,
|
||||
}, true
|
||||
}
|
||||
if expression, exists := licenseExpressionsByURL[url]; exists {
|
||||
return LicenseInfo{
|
||||
ID: expression,
|
||||
}, true
|
||||
}
|
||||
if normalized, ok := normalizeOpenSourceOrgURL(url); ok {
|
||||
if id, exists := openSourceOrgURLToLicense[normalized]; exists {
|
||||
return LicenseInfo{
|
||||
|
||||
@@ -41,6 +41,24 @@ func TestLicenseByURL(t *testing.T) {
|
||||
wantID: "BSD-3-Clause",
|
||||
wantFound: true,
|
||||
},
|
||||
{
|
||||
name: "GNU Classpath Exception URL",
|
||||
url: "https://www.gnu.org/software/classpath/license.html",
|
||||
wantID: "GPL-2.0-only WITH Classpath-exception-2.0",
|
||||
wantFound: true,
|
||||
},
|
||||
{
|
||||
name: "Eclipse secondary GPL Classpath URL",
|
||||
url: "https://projects.eclipse.org/license/secondary-gpl-2.0-cp",
|
||||
wantID: "GPL-2.0-only WITH Classpath-exception-2.0",
|
||||
wantFound: true,
|
||||
},
|
||||
{
|
||||
name: "Eclipse Public License legacy URL",
|
||||
url: "https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt",
|
||||
wantID: "EPL-2.0",
|
||||
wantFound: true,
|
||||
},
|
||||
{
|
||||
name: "URL with trailing whitespace",
|
||||
url: " http://opensource.org/licenses/MIT ",
|
||||
|
||||
@@ -554,12 +554,14 @@ func Test_deduplicateErrors(t *testing.T) {
|
||||
}
|
||||
|
||||
func Test_safeFileModeConvert(t *testing.T) {
|
||||
tests := []struct {
|
||||
type testCase struct {
|
||||
name string
|
||||
val int
|
||||
want fs.FileMode
|
||||
wantErr bool
|
||||
}{
|
||||
}
|
||||
|
||||
tests := []testCase{
|
||||
{
|
||||
// fs.go ModePerm 511 = FileMode = 0777 // Unix permission bits :192
|
||||
name: "valid perm",
|
||||
@@ -573,18 +575,29 @@ func Test_safeFileModeConvert(t *testing.T) {
|
||||
want: os.FileMode(0o1000000777), // 134218239
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "outside int32 high",
|
||||
val: int(math.MaxInt32) + 1,
|
||||
want: 0,
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "outside int32 low",
|
||||
val: int(math.MinInt32) - 1,
|
||||
want: 0,
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
|
||||
// Where int is 32 bits wide, no int value lies outside the int32 range, so
|
||||
// these two cases cannot be built at all. The bounds come from int64
|
||||
// variables rather than constants, because a constant that does not fit in
|
||||
// an int is a compile error on those platforms, not a skipped test.
|
||||
if math.MaxInt > math.MaxInt32 {
|
||||
maxInt32 := int64(math.MaxInt32)
|
||||
minInt32 := int64(math.MinInt32)
|
||||
tests = append(tests,
|
||||
testCase{
|
||||
name: "outside int32 high",
|
||||
val: int(maxInt32 + 1),
|
||||
want: 0,
|
||||
wantErr: true,
|
||||
},
|
||||
testCase{
|
||||
name: "outside int32 low",
|
||||
val: int(minInt32 - 1),
|
||||
want: 0,
|
||||
wantErr: true,
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
|
||||
@@ -1669,6 +1669,19 @@ func Test_Cataloger_PositiveCases(t *testing.T) {
|
||||
Metadata: metadata("bun-binary"),
|
||||
},
|
||||
},
|
||||
{
|
||||
// a compiled executable that mentions older Bun versions in embedded
|
||||
// text ("bun 1.0.0 to 1.3.9") before the runtime banner
|
||||
logicalFixture: "bun/1.4.4/darwin-arm64",
|
||||
expected: pkg.Package{
|
||||
Name: "bun",
|
||||
Version: "1.4.4",
|
||||
Type: "binary",
|
||||
PURL: "pkg:generic/bun@1.4.4",
|
||||
Locations: locations("bun"),
|
||||
Metadata: metadata("bun-binary"),
|
||||
},
|
||||
},
|
||||
{
|
||||
logicalFixture: "haskell-ghc/7.10.3/linux-amd64",
|
||||
expected: pkg.Package{
|
||||
@@ -3014,6 +3027,17 @@ func Test_Cataloger_PositiveCases(t *testing.T) {
|
||||
Metadata: metadata("elastic-agent-binary"),
|
||||
},
|
||||
},
|
||||
{
|
||||
logicalFixture: "julia/1.13.0-beta3/linux-amd64",
|
||||
expected: pkg.Package{
|
||||
Name: "julia",
|
||||
Version: "1.13.0-beta3",
|
||||
Type: "binary",
|
||||
PURL: "pkg:generic/julia@1.13.0-beta3",
|
||||
Locations: locations("libjulia-internal.so.1.13.0"),
|
||||
Metadata: metadata("julia-binary"),
|
||||
},
|
||||
},
|
||||
{
|
||||
logicalFixture: "julia/1.13.0-alpha2/linux-amd64",
|
||||
expected: pkg.Package{
|
||||
@@ -3036,6 +3060,17 @@ func Test_Cataloger_PositiveCases(t *testing.T) {
|
||||
Metadata: metadata("julia-binary"),
|
||||
},
|
||||
},
|
||||
{
|
||||
logicalFixture: "julia/1.12.4/linux-arm64",
|
||||
expected: pkg.Package{
|
||||
Name: "julia",
|
||||
Version: "1.12.4",
|
||||
Type: "binary",
|
||||
PURL: "pkg:generic/julia@1.12.4",
|
||||
Locations: locations("libjulia-internal.so.1.12.4"),
|
||||
Metadata: metadata("julia-binary"),
|
||||
},
|
||||
},
|
||||
{
|
||||
logicalFixture: "julia/1.11.9/linux-amd64",
|
||||
expected: pkg.Package{
|
||||
@@ -3047,6 +3082,17 @@ func Test_Cataloger_PositiveCases(t *testing.T) {
|
||||
Metadata: metadata("julia-binary"),
|
||||
},
|
||||
},
|
||||
{
|
||||
logicalFixture: "julia/1.11.6/linux-ppc64le",
|
||||
expected: pkg.Package{
|
||||
Name: "julia",
|
||||
Version: "1.11.6",
|
||||
Type: "binary",
|
||||
PURL: "pkg:generic/julia@1.11.6",
|
||||
Locations: locations("libjulia-internal.so.1.11.6"),
|
||||
Metadata: metadata("julia-binary"),
|
||||
},
|
||||
},
|
||||
{
|
||||
logicalFixture: "julia/1.10.11/linux-amd64",
|
||||
expected: pkg.Package{
|
||||
@@ -3058,6 +3104,50 @@ func Test_Cataloger_PositiveCases(t *testing.T) {
|
||||
Metadata: metadata("julia-binary"),
|
||||
},
|
||||
},
|
||||
{
|
||||
logicalFixture: "julia/1.10.4/linux-arm64",
|
||||
expected: pkg.Package{
|
||||
Name: "julia",
|
||||
Version: "1.10.4",
|
||||
Type: "binary",
|
||||
PURL: "pkg:generic/julia@1.10.4",
|
||||
Locations: locations("libjulia-internal.so.1.10.4"),
|
||||
Metadata: metadata("julia-binary"),
|
||||
},
|
||||
},
|
||||
{
|
||||
logicalFixture: "julia/1.9.0-beta3/linux-amd64",
|
||||
expected: pkg.Package{
|
||||
Name: "julia",
|
||||
Version: "1.9.0-beta3",
|
||||
Type: "binary",
|
||||
PURL: "pkg:generic/julia@1.9.0-beta3",
|
||||
Locations: locations("libjulia-internal.so.1.9"),
|
||||
Metadata: metadata("julia-binary"),
|
||||
},
|
||||
},
|
||||
{
|
||||
logicalFixture: "julia/1.9.0-beta3/linux-ppc64le",
|
||||
expected: pkg.Package{
|
||||
Name: "julia",
|
||||
Version: "1.9.0-beta3",
|
||||
Type: "binary",
|
||||
PURL: "pkg:generic/julia@1.9.0-beta3",
|
||||
Locations: locations("libjulia-internal.so.1.9"),
|
||||
Metadata: metadata("julia-binary"),
|
||||
},
|
||||
},
|
||||
{
|
||||
logicalFixture: "julia/1.9.0-beta2/linux-amd64",
|
||||
expected: pkg.Package{
|
||||
Name: "julia",
|
||||
Version: "1.9.0-beta2",
|
||||
Type: "binary",
|
||||
PURL: "pkg:generic/julia@1.9.0-beta2",
|
||||
Locations: locations("libjulia-internal.so.1.9"),
|
||||
Metadata: metadata("julia-binary"),
|
||||
},
|
||||
},
|
||||
{
|
||||
logicalFixture: "julia/1.9.0-alpha1/linux-amd64",
|
||||
expected: pkg.Package{
|
||||
@@ -3069,6 +3159,17 @@ func Test_Cataloger_PositiveCases(t *testing.T) {
|
||||
Metadata: metadata("julia-binary"),
|
||||
},
|
||||
},
|
||||
{
|
||||
logicalFixture: "julia/1.9.0-alpha1/linux-arm64",
|
||||
expected: pkg.Package{
|
||||
Name: "julia",
|
||||
Version: "1.9.0-alpha1",
|
||||
Type: "binary",
|
||||
PURL: "pkg:generic/julia@1.9.0-alpha1",
|
||||
Locations: locations("libjulia-internal.so.1.9"),
|
||||
Metadata: metadata("julia-binary"),
|
||||
},
|
||||
},
|
||||
{
|
||||
logicalFixture: "julia/1.8.5/linux-amd64",
|
||||
expected: pkg.Package{
|
||||
@@ -3080,6 +3181,17 @@ func Test_Cataloger_PositiveCases(t *testing.T) {
|
||||
Metadata: metadata("julia-binary"),
|
||||
},
|
||||
},
|
||||
{
|
||||
logicalFixture: "julia/1.8.5/linux-arm64",
|
||||
expected: pkg.Package{
|
||||
Name: "julia",
|
||||
Version: "1.8.5",
|
||||
Type: "binary",
|
||||
PURL: "pkg:generic/julia@1.8.5",
|
||||
Locations: locations("libjulia-internal.so.1.8"),
|
||||
Metadata: metadata("julia-binary"),
|
||||
},
|
||||
},
|
||||
{
|
||||
// note: dynamic (non-snippet) test case
|
||||
logicalFixture: "julia/1.5.4/linux-amd64",
|
||||
@@ -3324,6 +3436,7 @@ func Test_Cataloger_DefaultClassifiers_PositiveCases_Image(t *testing.T) {
|
||||
// must stay truncated: it sorts below the release in semver and would corrupt
|
||||
// version-range matching. Suffix-free binaries match exactly as before, and
|
||||
// trailing non-version text (or NUL padding) is never absorbed into the version.
|
||||
// Libraries that only carry libavcodec/libavformat API idents are not reported.
|
||||
func Test_Cataloger_ffmpeg_versionSuffix(t *testing.T) {
|
||||
// collect the ffmpeg classifiers under test, keyed by their FileGlob
|
||||
classifiers := map[string]binutils.Classifier{}
|
||||
@@ -3391,6 +3504,27 @@ func Test_Cataloger_ffmpeg_versionSuffix(t *testing.T) {
|
||||
data: "FFmpeg version 9.0.3\x00libavformat.so",
|
||||
want: "9.0.3",
|
||||
},
|
||||
{
|
||||
// "Lavc"/"Lavf" idents carry the libavcodec/libavformat API version, which is
|
||||
// versioned independently of FFmpeg releases, so they must not be reported as
|
||||
// the ffmpeg version. The diagnostic text has no release number either.
|
||||
name: "library with only libavcodec and libavformat idents not reported",
|
||||
fileGlob: "**/libav*",
|
||||
data: "Lavc62.28.102\x00Lavf62.12.102\x00Please update your FFmpeg version to the newest one from Git",
|
||||
want: "",
|
||||
},
|
||||
{
|
||||
name: "library with only libavformat ident not reported",
|
||||
fileGlob: "**/libav*",
|
||||
data: "Lavf62.12.102",
|
||||
want: "",
|
||||
},
|
||||
{
|
||||
name: "library release version used even when libavcodec ident appears first",
|
||||
fileGlob: "**/libav*",
|
||||
data: "Lavc61.19.101\x00FFmpeg version 7.1.1",
|
||||
want: "7.1.1",
|
||||
},
|
||||
{
|
||||
name: "libswresample build metadata preserved",
|
||||
fileGlob: "**/libswresample*",
|
||||
|
||||
@@ -110,12 +110,16 @@ func DefaultClassifiers() []binutils.Classifier {
|
||||
// [NUL]GIT_VERSION_INFO[NUL]__init__[NUL]1.12.6[NUL]branch[NUL]commit
|
||||
// [NUL]GIT_VERSION_INFO[NUL]__init__[NUL]verify_methods[NUL]1.11.9[NUL]branch[NUL]commit
|
||||
// [NUL][NUL]__init__[NUL]1.10.11[NUL]verify_methods[NUL]
|
||||
m.FileContentsVersionMatcher(`\x00__init__\x00(?P<version>[0-9]+\.[0-9]+\.[0-9]+(-alpha[0-9]|-beta[0-9]|-rc[0-9])?)\x00(branch|verify_methods)`),
|
||||
m.FileContentsVersionMatcher(`(?P<version>[0-9]+\.[0-9]+\.[0-9]+(-alpha[0-9]|-beta[0-9]|-rc[0-9])?)\x00branch\x00`),
|
||||
// [NUL]verify_methods[NUL]Task cannot be serialized[NUL]1.9.0-alpha1[NUL]BigInt[NUL]
|
||||
m.FileContentsVersionMatcher(`\x00verify_methods\x00.{0,30}(?P<version>[0-9]+\.[0-9]+\.[0-9]+(-alpha[0-9]|-beta[0-9]|-rc[0-9])?)\x00BigInt`),
|
||||
// unknown option `%s`[NUL]1.8.5[NUL]julia version %s
|
||||
m.FileContentsVersionMatcher(`\x00(?P<version>[0-9]+\.[0-9]+\.[0-9]+(-alpha[0-9]|-beta[0-9]|-rc[0-9])?)\x00julia version`),
|
||||
// [NUL]1.9.0-beta3[NUL]__init__[NUL]verify_methods
|
||||
// arm64/ppc64le put NUL runs between strings, what precedes the version varies: only the trailing token is anchored
|
||||
// single-digit major (fine while julia is 1.x): on ppc64le 1.9.0-beta3 a run of ASCII '0's precedes the version
|
||||
m.FileContentsVersionMatcher(`(?P<version>[0-9]\.[0-9]+\.[0-9]+(-alpha[0-9]|-beta[0-9]|-rc[0-9])?)\x00+(branch|verify_methods|__init__)\x00`),
|
||||
// [NUL]Task cannot be serialized[NUL]1.9.0-alpha1[NUL]BigInt[NUL] (amd64)
|
||||
// [NUL x8]1.9.0-alpha1[NUL x4]Precompile file header verification checks failed.[NUL x6]BigInt[NUL] (arm64)
|
||||
// NUL runs follow the version on arm64/ppc64le; arm64: no NUL-delimited verify_methods nearby, a string before BigInt
|
||||
m.FileContentsVersionMatcher(`\x00(?P<version>[0-9]\.[0-9]+\.[0-9]+(-alpha[0-9]|-beta[0-9]|-rc[0-9])?)\x00+([^\x00]+\x00+)?BigInt\x00`),
|
||||
// unknown option `%s`[NUL]1.8.5[NUL]julia version %s (arm64/ppc64le: [NUL x5]1.8.5[NUL x3]julia version)
|
||||
m.FileContentsVersionMatcher(`\x00(?P<version>[0-9]+\.[0-9]+\.[0-9]+(-alpha[0-9]|-beta[0-9]|-rc[0-9])?)\x00+julia version`),
|
||||
),
|
||||
Package: "julia",
|
||||
PURL: mustPURL("pkg:generic/julia@version"),
|
||||
@@ -130,11 +134,13 @@ func DefaultClassifiers() []binutils.Classifier {
|
||||
// libjulia.so
|
||||
`^libjulia\.so(\.[0-9])?(\.[0-9])?$`,
|
||||
binutils.MatchAny(
|
||||
// unknown option `%s`[NUL]1.5.4[NUL]julia version %s
|
||||
m.FileContentsVersionMatcher(`\x00(?P<version>[0-9]+\.[0-9]+\.[0-9]+(-alpha[0-9]|-beta[0-9]|-rc[0-9])?)\x00julia version`),
|
||||
// unknown option `%s`[NUL]1.5.4[NUL]julia version %s (arm64/ppc64le: [NUL x5]1.5.4[NUL x3]julia version)
|
||||
m.FileContentsVersionMatcher(`\x00(?P<version>[0-9]+\.[0-9]+\.[0-9]+(-alpha[0-9]|-beta[0-9]|-rc[0-9])?)\x00+julia version`),
|
||||
// [NUL]#kw#[NUL]1.3.1[NUL]BigInt
|
||||
// [NUL]#kw#[NUL]0.7.0-beta2[NUL]_require_dependencies
|
||||
m.FileContentsVersionMatcher(`\x00#kw#\x00(?P<version>[0-9]+\.[0-9]+\.[0-9]+(-alpha[0-9]|-beta[0-9]|-rc[0-9])?)\x00(BigInt|_require_dependencies)`),
|
||||
// [NUL x7]1.3.1[NUL x3]Precompile file header verification checks failed.[NUL x6]BigInt[NUL] (arm64, no #kw# nearby)
|
||||
m.FileContentsVersionMatcher(`\x00(?P<version>[0-9]\.[0-9]+\.[0-9]+(-alpha[0-9]|-beta[0-9]|-rc[0-9])?)\x00+([^\x00]+\x00+)?BigInt\x00`),
|
||||
// [NUL]ObjectIdDict[NUL]0.6.4[NUL]jl_sysimg_cpu_target
|
||||
m.FileContentsVersionMatcher(`\x00ObjectIdDict\x00(?P<version>[0-9]+\.[0-9]+\.[0-9]+(-alpha[0-9]|-beta[0-9]|-rc[0-9])?)\x00jl_sysimg_cpu_target`),
|
||||
// [NUL]require[NUL]0.4.6[NUL]core2
|
||||
@@ -636,11 +642,14 @@ func DefaultClassifiers() []binutils.Classifier {
|
||||
Class: "bun-binary",
|
||||
FileGlob: "**/bun",
|
||||
EvidenceMatcher: binutils.MatchAny(
|
||||
// bun 1.1.0
|
||||
// Bun v1.0.0
|
||||
m.FileContentsVersionMatcher(`(?m)[Bb]un v?(?P<version>[0-9]+\.[0-9]+\.[0-9]+)`),
|
||||
// Bun v1.0.0 (the runtime banner). This is checked first because
|
||||
// compiled executables can embed other text that mentions older Bun
|
||||
// versions without the "v" (e.g. "bun 1.0.0 to 1.3.9") before the banner.
|
||||
m.FileContentsVersionMatcher(`(?m)[Bb]un v(?P<version>[0-9]+\.[0-9]+\.[0-9]+)`),
|
||||
// bun-1.1.0
|
||||
m.FileContentsVersionMatcher(`(?m)bun-(?P<version>[0-9]+\.[0-9]+\.[0-9]+)`),
|
||||
// bun 1.1.0
|
||||
m.FileContentsVersionMatcher(`(?m)[Bb]un (?P<version>[0-9]+\.[0-9]+\.[0-9]+)`),
|
||||
),
|
||||
Package: "bun",
|
||||
PURL: mustPURL("pkg:generic/bun@version"),
|
||||
@@ -984,8 +993,8 @@ func DefaultClassifiers() []binutils.Classifier {
|
||||
{
|
||||
Class: "ffmpeg-library",
|
||||
FileGlob: "**/libav*",
|
||||
EvidenceMatcher: binutils.MatchAny(
|
||||
// Primary pattern: FFmpeg version found in most libraries.
|
||||
EvidenceMatcher: m.FileContentsVersionMatcher(
|
||||
// FFmpeg version found in most libraries.
|
||||
// The optional "+" suffix preserves semver build metadata (e.g. a
|
||||
// backported-patch stamp like "9.0.3+dev.9.0.2.p1.eb9cef3") instead of
|
||||
// truncating to X.Y[.Z]. Build metadata compares equal to its core
|
||||
@@ -993,11 +1002,11 @@ func DefaultClassifiers() []binutils.Classifier {
|
||||
// pre-release suffix (e.g. a distro revision "6.1.1-3ubuntu5") is
|
||||
// deliberately NOT captured: it sorts below the release in semver and
|
||||
// would corrupt version-range matching, so it stays truncated as before.
|
||||
m.FileContentsVersionMatcher(`(?m)FFmpeg version (?P<version>[0-9]+\.[0-9]+(\.[0-9]+)?(?:\+[0-9A-Za-z]+(?:\.[0-9A-Za-z]+)*)?)`),
|
||||
// Fallback: library-specific version patterns for libavcodec and libavformat
|
||||
m.FileContentsVersionMatcher(`(?m)Lavc(?P<version>[0-9]+\.[0-9]+\.[0-9]+)`),
|
||||
m.FileContentsVersionMatcher(`(?m)Lavf(?P<version>[0-9]+\.[0-9]+\.[0-9]+)`),
|
||||
),
|
||||
// Library idents such as "Lavc62.28.102" or "Lavf62.12.102" are not used
|
||||
// as a fallback: they carry the libavcodec/libavformat API version, which
|
||||
// is versioned independently of FFmpeg releases and would produce a wrong
|
||||
// ffmpeg PURL and CPE.
|
||||
`(?m)FFmpeg version (?P<version>[0-9]+\.[0-9]+(\.[0-9]+)?(?:\+[0-9A-Za-z]+(?:\.[0-9A-Za-z]+)*)?)`),
|
||||
Package: "ffmpeg",
|
||||
PURL: mustPURL("pkg:generic/ffmpeg@version"),
|
||||
CPEs: singleCPE("cpe:2.3:a:ffmpeg:ffmpeg:*:*:*:*:*:*:*:*", cpe.NVDDictionaryLookupSource),
|
||||
|
||||
@@ -223,6 +223,11 @@ func getPlatformElf(f *os.File) string {
|
||||
arch = "386"
|
||||
case elf.EM_RISCV:
|
||||
arch = "riscv64"
|
||||
case elf.EM_PPC64:
|
||||
arch = "ppc64le"
|
||||
if elfFile.Data == elf.ELFDATA2MSB {
|
||||
arch = "ppc64"
|
||||
}
|
||||
// TODO...
|
||||
default:
|
||||
arch = fmt.Sprintf("unknown-%x", elfFile.Machine)
|
||||
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
name: bun
|
||||
offset: 1000000
|
||||
length: 100
|
||||
snippetSha256: 0000000000000000000000000000000000000000000000000000000000000005
|
||||
fileSha256: 0000000000000000000000000000000000000000000000000000000000000005
|
||||
|
||||
### byte snippet to follow ###
|
||||
]
|
||||
|
||||
supported for bun 1.0.0 to 1.3.9
|
||||
Bun v1.4.4 (424a542a9) macOS Silicon
|
||||
Vendored
Symlink
+1
@@ -0,0 +1 @@
|
||||
libjulia-internal.so.1.10.4
|
||||
BIN
Binary file not shown.
Vendored
Symlink
+1
@@ -0,0 +1 @@
|
||||
libjulia-internal.so.1.11.6
|
||||
BIN
Binary file not shown.
Vendored
Symlink
+1
@@ -0,0 +1 @@
|
||||
libjulia-internal.so.1.12.4
|
||||
BIN
Binary file not shown.
syft/pkg/cataloger/binary/testdata/classifiers/snippets/julia/1.8.5/linux-arm64/libjulia-internal.so
Vendored
Symlink
+1
@@ -0,0 +1 @@
|
||||
libjulia-internal.so.1.8
|
||||
BIN
Binary file not shown.
Vendored
Symlink
+1
@@ -0,0 +1 @@
|
||||
libjulia-internal.so.1.9
|
||||
BIN
Binary file not shown.
Vendored
Symlink
+1
@@ -0,0 +1 @@
|
||||
libjulia-internal.so.1.9
|
||||
BIN
Binary file not shown.
Vendored
Symlink
+1
@@ -0,0 +1 @@
|
||||
libjulia-internal.so.1.9
|
||||
BIN
Binary file not shown.
Vendored
Symlink
+1
@@ -0,0 +1 @@
|
||||
libjulia-internal.so.1.9
|
||||
BIN
Binary file not shown.
+53
@@ -1768,6 +1768,15 @@ from-images:
|
||||
- /usr/local/julia/lib/julia/libjulia-internal.so
|
||||
- /usr/local/julia/lib/julia/libjulia-internal.so.1.12.6
|
||||
|
||||
- name: julia
|
||||
version: 1.12.4
|
||||
images:
|
||||
- ref: library/julia:1.12.4@sha256:1339c3a525d63f7089e9d51aa7dce030d432a2b9111cb2350cb6a6202f796ad1
|
||||
platform: linux/arm64
|
||||
paths:
|
||||
- /usr/local/julia/lib/julia/libjulia-internal.so
|
||||
- /usr/local/julia/lib/julia/libjulia-internal.so.1.12.4
|
||||
|
||||
- name: julia
|
||||
version: 1.11.9
|
||||
images:
|
||||
@@ -1777,6 +1786,15 @@ from-images:
|
||||
- /usr/local/julia/lib/julia/libjulia-internal.so
|
||||
- /usr/local/julia/lib/julia/libjulia-internal.so.1.11.9
|
||||
|
||||
- name: julia
|
||||
version: 1.11.6
|
||||
images:
|
||||
- ref: library/julia:1.11.6@sha256:6a7f5e2b5f9c43b8ea6023df4c46edaf14dbc6d3f40562545a63a2f32316c06a
|
||||
platform: linux/ppc64le
|
||||
paths:
|
||||
- /usr/local/julia/lib/julia/libjulia-internal.so
|
||||
- /usr/local/julia/lib/julia/libjulia-internal.so.1.11.6
|
||||
|
||||
- name: julia
|
||||
version: 1.10.11
|
||||
images:
|
||||
@@ -1786,11 +1804,44 @@ from-images:
|
||||
- /usr/local/julia/lib/julia/libjulia-internal.so
|
||||
- /usr/local/julia/lib/julia/libjulia-internal.so.1.10.11
|
||||
|
||||
- name: julia
|
||||
version: 1.10.4
|
||||
images:
|
||||
- ref: library/julia:1.10.4@sha256:101e6819484e693032933cefcffe246ee12a5f4a790da69555c821e89f566820
|
||||
platform: linux/arm64
|
||||
paths:
|
||||
- /usr/local/julia/lib/julia/libjulia-internal.so
|
||||
- /usr/local/julia/lib/julia/libjulia-internal.so.1.10.4
|
||||
|
||||
- name: julia
|
||||
version: 1.9.0-beta3
|
||||
images:
|
||||
# note: per-platform manifest digests (not the index digest) -- the extraction step creates a
|
||||
# container from the ref alone, so each platform needs its own uniquely addressable ref
|
||||
- ref: library/julia:1.9.0-beta3@sha256:1bf66d7f6120cd0e75ce6198f5e0247de8e8448ebdc1bc319da750457c23788f
|
||||
platform: linux/amd64
|
||||
- ref: library/julia:1.9.0-beta3@sha256:4667273a351b6db5867686cf9618a42a7d62108f478ebb251a922d834f113916
|
||||
platform: linux/ppc64le
|
||||
paths:
|
||||
- /usr/local/julia/lib/julia/libjulia-internal.so
|
||||
- /usr/local/julia/lib/julia/libjulia-internal.so.1.9
|
||||
|
||||
- name: julia
|
||||
version: 1.9.0-beta2
|
||||
images:
|
||||
- ref: library/julia:1.9.0-beta2@sha256:7877eae88f51a50344c0163b9bbf66bf172aafb1f886fe558c12a55a51a26780
|
||||
platform: linux/amd64
|
||||
paths:
|
||||
- /usr/local/julia/lib/julia/libjulia-internal.so
|
||||
- /usr/local/julia/lib/julia/libjulia-internal.so.1.9
|
||||
|
||||
- name: julia
|
||||
version: 1.9.0-alpha1
|
||||
images:
|
||||
- ref: library/julia:1.9.0-alpha1@sha256:fb932603485d7cea435e85c073c04bdf4d0b90232c03013585aa0f65c8216111
|
||||
platform: linux/amd64
|
||||
- ref: library/julia:1.9.0-alpha1@sha256:a219a720fddbcb6d589127f2ea40bee2e66eab9157645ec753010048f1d8cc17
|
||||
platform: linux/arm64
|
||||
paths:
|
||||
- /usr/local/julia/lib/julia/libjulia-internal.so
|
||||
- /usr/local/julia/lib/julia/libjulia-internal.so.1.9
|
||||
@@ -1800,6 +1851,8 @@ from-images:
|
||||
images:
|
||||
- ref: library/julia:1.8.5@sha256:5edccd0ca0b5f00d78beca0bd8217d65b2c24ef051ad07e2b08ed67224ff905a
|
||||
platform: linux/amd64
|
||||
- ref: library/julia:1.8.5@sha256:edd1f4415b619d95f4503fa04a589dd79b0e6f91e26006391729c6661d767c78
|
||||
platform: linux/arm64
|
||||
paths:
|
||||
- /usr/local/julia/lib/julia/libjulia-internal.so
|
||||
- /usr/local/julia/lib/julia/libjulia-internal.so.1.8
|
||||
|
||||
@@ -15,7 +15,9 @@ func NewDBCataloger() pkg.Cataloger {
|
||||
// note: these globs have been intentionally split up in order to improve search performance,
|
||||
// please do NOT combine into: "**/var/lib/dpkg/{status,status.d/*}"
|
||||
WithParserByGlobs(parseDpkgDB, "**/lib/dpkg/status", "**/lib/dpkg/status.d/*", "**/lib/opkg/info/*.control", "**/lib/opkg/status").
|
||||
WithProcessors(dependency.Processor(dbEntryDependencySpecifier))
|
||||
// registration order is execution order: the merge has to precede dependency resolution, so that
|
||||
// relationships are only created for the packages that are kept
|
||||
WithProcessors(mergeStatusDirDuplicates, dependency.Processor(dbEntryDependencySpecifier))
|
||||
}
|
||||
|
||||
// NewArchiveCataloger returns a new Debian package cataloger object capable of parsing .deb and .ipk (opkg) archive files
|
||||
|
||||
@@ -290,7 +290,7 @@ func fetchMd5Contents(resolver file.Resolver, dbLocation file.Location, m pkg.Dp
|
||||
// the same directory
|
||||
searchPath := filepath.Dir(dbLocation.LocalPath())
|
||||
|
||||
if !strings.HasSuffix(searchPath, "status.d") {
|
||||
if !strings.HasSuffix(searchPath, statusDirName) {
|
||||
searchPath = path.Join(searchPath, "info")
|
||||
}
|
||||
|
||||
|
||||
@@ -63,7 +63,7 @@ func findDpkgInfoFiles(name string, resolver file.Resolver, dbLocation file.Loca
|
||||
// the same directory
|
||||
searchPath := path.Dir(dbLocation.LocalPath())
|
||||
|
||||
if !strings.HasSuffix(searchPath, "status.d") {
|
||||
if !strings.HasSuffix(searchPath, statusDirName) {
|
||||
searchPath = path.Join(searchPath, "info")
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,243 @@
|
||||
package debian
|
||||
|
||||
import (
|
||||
"maps"
|
||||
"path"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/anchore/syft/internal/relationship"
|
||||
"github.com/anchore/syft/syft/artifact"
|
||||
"github.com/anchore/syft/syft/file"
|
||||
"github.com/anchore/syft/syft/pkg"
|
||||
)
|
||||
|
||||
const (
|
||||
statusFileName = "status"
|
||||
statusDirName = "status.d"
|
||||
)
|
||||
|
||||
// dpkgEntryKey identifies one installed package within one dpkg database directory.
|
||||
type dpkgEntryKey struct {
|
||||
// container is the archive the database was found in, if any, so that databases at the same path within
|
||||
// different archives are kept apart
|
||||
container string
|
||||
dbDir string
|
||||
name string
|
||||
version string
|
||||
architecture string
|
||||
}
|
||||
|
||||
// mergeStatusDirDuplicates folds packages described by a status.d/<name> file into the package described by the
|
||||
// status file of the same dpkg database, when both describe the same name, version and architecture. Some images
|
||||
// record every installed package in both places, which would otherwise report each package twice.
|
||||
//
|
||||
// The status file stays the primary evidence of the merged package, and the status.d file becomes supporting evidence.
|
||||
//
|
||||
// When several layers are cataloged, the status file can be seen once per layer. Every one of those packages receives
|
||||
// the status.d package, so they keep a common ID and still collapse into one package downstream.
|
||||
func mergeStatusDirDuplicates(pkgs []pkg.Package, rels []artifact.Relationship, err error) ([]pkg.Package, []artifact.Relationship, error) {
|
||||
// the package that each package was merged into, and the status.d packages no longer reported on their own
|
||||
mergedInto := make(map[int]pkg.Package)
|
||||
dropped := make(map[int]bool)
|
||||
for _, e := range groupDpkgEntries(pkgs) {
|
||||
if len(e.status) == 0 || len(e.statusDir) == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
// copies of the status entry from different layers share an ID, and only the first annotation seen survives
|
||||
// when they collapse downstream, so they must all agree on the evidence of the status.d entry
|
||||
statusVisible := false
|
||||
for _, i := range e.status {
|
||||
if l, ok := primaryEvidence(pkgs[i]); ok && isVisible(l) {
|
||||
statusVisible = true
|
||||
}
|
||||
}
|
||||
|
||||
for _, target := range e.status {
|
||||
m := pkgs[target]
|
||||
for _, i := range e.statusDir {
|
||||
m = mergeStatusDirPackage(m, pkgs[i], statusVisible)
|
||||
}
|
||||
m.SetID()
|
||||
mergedInto[target] = m
|
||||
}
|
||||
for _, i := range e.statusDir {
|
||||
dropped[i] = true
|
||||
// every status copy carries the same merged ID, so any of them will do
|
||||
mergedInto[i] = mergedInto[e.status[0]]
|
||||
}
|
||||
}
|
||||
if len(dropped) == 0 {
|
||||
return pkgs, rels, err
|
||||
}
|
||||
|
||||
kept := make([]pkg.Package, 0, len(pkgs)-len(dropped))
|
||||
for i, p := range pkgs {
|
||||
if dropped[i] {
|
||||
continue
|
||||
}
|
||||
if m, isMerged := mergedInto[i]; isMerged {
|
||||
p = m
|
||||
}
|
||||
kept = append(kept, p)
|
||||
}
|
||||
|
||||
return kept, followMergedPackages(rels, pkgs, mergedInto), err
|
||||
}
|
||||
|
||||
// dpkgEntry holds the indexes of the packages describing one dpkg entry, in package order so that merging is
|
||||
// deterministic.
|
||||
type dpkgEntry struct {
|
||||
status, statusDir []int
|
||||
}
|
||||
|
||||
func groupDpkgEntries(pkgs []pkg.Package) map[dpkgEntryKey]*dpkgEntry {
|
||||
entries := make(map[dpkgEntryKey]*dpkgEntry)
|
||||
for i, p := range pkgs {
|
||||
key, inStatusDir, ok := dpkgKey(p)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
e := entries[key]
|
||||
if e == nil {
|
||||
e = &dpkgEntry{}
|
||||
entries[key] = e
|
||||
}
|
||||
if inStatusDir {
|
||||
e.statusDir = append(e.statusDir, i)
|
||||
} else {
|
||||
e.status = append(e.status, i)
|
||||
}
|
||||
}
|
||||
return entries
|
||||
}
|
||||
|
||||
// followMergedPackages points relationships at the package that each package was merged into, since merging drops
|
||||
// status.d packages and changes the ID of the status packages they were folded into.
|
||||
func followMergedPackages(rels []artifact.Relationship, pkgs []pkg.Package, mergedInto map[int]pkg.Package) []artifact.Relationship {
|
||||
if len(rels) == 0 {
|
||||
return rels
|
||||
}
|
||||
idx := relationship.NewIndex(rels...)
|
||||
for i, m := range mergedInto {
|
||||
idx.Replace(pkgs[i].ID(), m)
|
||||
}
|
||||
return idx.All()
|
||||
}
|
||||
|
||||
// mergeStatusDirPackage returns the package read from the status file with the evidence, licenses and file listing
|
||||
// of the same package read from status.d folded into it. The remaining metadata of the status entry is kept as is.
|
||||
// statusVisible reports whether any copy of the status entry is visible in the final filesystem.
|
||||
func mergeStatusDirPackage(fromStatus, fromStatusDir pkg.Package, statusVisible bool) pkg.Package {
|
||||
// when no copy of the status entry is visible in the final filesystem but the status.d file is, the status.d file
|
||||
// is what shows that the package is still installed, so it has to stay primary evidence
|
||||
statusDirLocation, ok := primaryEvidence(fromStatusDir)
|
||||
keepPrimary := ok && isVisible(statusDirLocation) && !statusVisible
|
||||
|
||||
locations := file.NewLocationSet()
|
||||
for _, l := range fromStatus.Locations.ToSlice() {
|
||||
locations.Add(withCopiedAnnotations(l))
|
||||
}
|
||||
for _, l := range fromStatusDir.Locations.ToSlice() {
|
||||
l = withCopiedAnnotations(l)
|
||||
if !keepPrimary && l.Annotations[pkg.EvidenceAnnotationKey] == pkg.PrimaryEvidenceAnnotation {
|
||||
l.Annotations[pkg.EvidenceAnnotationKey] = pkg.SupportingEvidenceAnnotation
|
||||
}
|
||||
locations.Add(l)
|
||||
}
|
||||
fromStatus.Locations = locations
|
||||
|
||||
licenses := pkg.NewLicenseSet(fromStatus.Licenses.ToSlice()...)
|
||||
licenses.Add(fromStatusDir.Licenses.ToSlice()...)
|
||||
fromStatus.Licenses = licenses
|
||||
|
||||
// the file listing is read from beside whichever file described the package (info/ for status, status.d/ itself
|
||||
// otherwise), so the status entry can be missing files that only the status.d entry knows about
|
||||
from, fromOK := fromStatusDir.Metadata.(pkg.DpkgDBEntry)
|
||||
into, intoOK := fromStatus.Metadata.(pkg.DpkgDBEntry)
|
||||
if fromOK && intoOK && len(from.Files) > 0 {
|
||||
into.Files = mergeDpkgFileRecords(into.Files, from.Files)
|
||||
fromStatus.Metadata = into
|
||||
}
|
||||
|
||||
return fromStatus
|
||||
}
|
||||
|
||||
// withCopiedAnnotations returns the location with its own copy of the annotations, which are otherwise a map shared
|
||||
// with every copy of the location.
|
||||
func withCopiedAnnotations(l file.Location) file.Location {
|
||||
annotations := make(map[string]string, len(l.Annotations))
|
||||
maps.Copy(annotations, l.Annotations)
|
||||
l.Annotations = annotations
|
||||
return l
|
||||
}
|
||||
|
||||
// mergeDpkgFileRecords returns the existing records plus any additional records for paths not already present,
|
||||
// sorted by path.
|
||||
func mergeDpkgFileRecords(existing, additional []pkg.DpkgFileRecord) []pkg.DpkgFileRecord {
|
||||
paths := make(map[string]struct{}, len(existing))
|
||||
files := make([]pkg.DpkgFileRecord, 0, len(existing)+len(additional))
|
||||
for _, f := range existing {
|
||||
paths[f.Path] = struct{}{}
|
||||
files = append(files, f)
|
||||
}
|
||||
for _, f := range additional {
|
||||
if _, exists := paths[f.Path]; exists {
|
||||
continue
|
||||
}
|
||||
paths[f.Path] = struct{}{}
|
||||
files = append(files, f)
|
||||
}
|
||||
sort.SliceStable(files, func(i, j int) bool {
|
||||
return files[i].Path < files[j].Path
|
||||
})
|
||||
return files
|
||||
}
|
||||
|
||||
// dpkgKey returns the identity of a dpkg DB package and whether it was read from a status.d directory. ok is false
|
||||
// for packages that did not come from a dpkg status file or status.d directory.
|
||||
func dpkgKey(p pkg.Package) (key dpkgEntryKey, inStatusDir bool, ok bool) {
|
||||
entry, isDpkgEntry := p.Metadata.(pkg.DpkgDBEntry)
|
||||
if !isDpkgEntry {
|
||||
return dpkgEntryKey{}, false, false
|
||||
}
|
||||
dbLocation, hasPrimary := primaryEvidence(p)
|
||||
if !hasPrimary {
|
||||
return dpkgEntryKey{}, false, false
|
||||
}
|
||||
|
||||
// for a database within an archive the real path is that of the archive, so the path within it is used
|
||||
localPath := dbLocation.LocalPath()
|
||||
dir := path.Dir(localPath)
|
||||
inStatusDir = path.Base(dir) == statusDirName
|
||||
switch {
|
||||
case inStatusDir:
|
||||
dir = path.Dir(dir)
|
||||
case path.Base(localPath) != statusFileName:
|
||||
return dpkgEntryKey{}, false, false
|
||||
}
|
||||
|
||||
return dpkgEntryKey{
|
||||
container: strings.TrimSuffix(dbLocation.FullNestedPath(), localPath),
|
||||
dbDir: dir,
|
||||
name: p.Name,
|
||||
version: p.Version,
|
||||
architecture: entry.Architecture,
|
||||
}, inStatusDir, true
|
||||
}
|
||||
|
||||
func primaryEvidence(p pkg.Package) (file.Location, bool) {
|
||||
for _, l := range p.Locations.ToSlice() {
|
||||
if l.Annotations[pkg.EvidenceAnnotationKey] == pkg.PrimaryEvidenceAnnotation {
|
||||
return l, true
|
||||
}
|
||||
}
|
||||
return file.Location{}, false
|
||||
}
|
||||
|
||||
// isVisible reports whether a location is marked as present in the final filesystem. Locations carry no such mark
|
||||
// unless the scan distinguishes hidden files from visible ones.
|
||||
func isVisible(l file.Location) bool {
|
||||
return l.Annotations[file.VisibleAnnotationKey] == file.VisibleAnnotation
|
||||
}
|
||||
@@ -0,0 +1,588 @@
|
||||
package debian
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/anchore/syft/syft/artifact"
|
||||
"github.com/anchore/syft/syft/file"
|
||||
"github.com/anchore/syft/syft/pkg"
|
||||
"github.com/anchore/syft/syft/pkg/cataloger/internal/pkgtest"
|
||||
)
|
||||
|
||||
func dpkgTestPackage(name, version, arch, dbPath string, evidence ...string) pkg.Package {
|
||||
locations := file.NewLocationSet(
|
||||
file.NewLocation(dbPath).WithAnnotation(pkg.EvidenceAnnotationKey, pkg.PrimaryEvidenceAnnotation),
|
||||
)
|
||||
for _, e := range evidence {
|
||||
locations.Add(file.NewLocation(e).WithAnnotation(pkg.EvidenceAnnotationKey, pkg.SupportingEvidenceAnnotation))
|
||||
}
|
||||
p := pkg.Package{
|
||||
Name: name,
|
||||
Version: version,
|
||||
Type: pkg.DebPkg,
|
||||
Locations: locations,
|
||||
Metadata: pkg.DpkgDBEntry{
|
||||
Package: name,
|
||||
Version: version,
|
||||
Architecture: arch,
|
||||
},
|
||||
}
|
||||
p.SetID()
|
||||
return p
|
||||
}
|
||||
|
||||
// dpkgTestPackageAt is dpkgTestPackage with full control over the database location.
|
||||
func dpkgTestPackageAt(name, version, arch string, dbLocation file.Location) pkg.Package {
|
||||
p := dpkgTestPackage(name, version, arch, dbLocation.RealPath)
|
||||
p.Locations = file.NewLocationSet(dbLocation.WithAnnotation(pkg.EvidenceAnnotationKey, pkg.PrimaryEvidenceAnnotation))
|
||||
p.SetID()
|
||||
return p
|
||||
}
|
||||
|
||||
func locationPaths(p pkg.Package) []string {
|
||||
var paths []string
|
||||
for _, l := range p.Locations.ToSlice() {
|
||||
paths = append(paths, l.RealPath)
|
||||
}
|
||||
sort.Strings(paths)
|
||||
return paths
|
||||
}
|
||||
|
||||
// evidencePaths returns the location paths of a package carrying the given evidence annotation.
|
||||
func evidencePaths(p pkg.Package, evidence string) []string {
|
||||
var paths []string
|
||||
for _, l := range p.Locations.ToSlice() {
|
||||
if l.Annotations[pkg.EvidenceAnnotationKey] == evidence {
|
||||
paths = append(paths, l.RealPath)
|
||||
}
|
||||
}
|
||||
sort.Strings(paths)
|
||||
return paths
|
||||
}
|
||||
|
||||
// describe renders a package as "name@version (arch): location, location" for comparison.
|
||||
func describe(p pkg.Package) string {
|
||||
return fmt.Sprintf("%s@%s (%s): %s", p.Name, p.Version, p.Metadata.(pkg.DpkgDBEntry).Architecture, strings.Join(locationPaths(p), ", "))
|
||||
}
|
||||
|
||||
func Test_mergeStatusDirDuplicates(t *testing.T) {
|
||||
const (
|
||||
status = "/var/lib/dpkg/status"
|
||||
statusDir = "/var/lib/dpkg/status.d/"
|
||||
)
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
pkgs []pkg.Package
|
||||
expected []string
|
||||
}{
|
||||
{
|
||||
name: "same package in status and status.d is reported once with both locations",
|
||||
pkgs: []pkg.Package{
|
||||
dpkgTestPackage("gzip", "1.13-1", "arm64", statusDir+"gzip"),
|
||||
dpkgTestPackage("gzip", "1.13-1", "arm64", status, "/var/lib/dpkg/info/gzip.md5sums"),
|
||||
},
|
||||
expected: []string{
|
||||
"gzip@1.13-1 (arm64): /var/lib/dpkg/info/gzip.md5sums, /var/lib/dpkg/status, /var/lib/dpkg/status.d/gzip",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "order of discovery does not matter",
|
||||
pkgs: []pkg.Package{
|
||||
dpkgTestPackage("gzip", "1.13-1", "arm64", status),
|
||||
dpkgTestPackage("gzip", "1.13-1", "arm64", statusDir+"gzip"),
|
||||
},
|
||||
expected: []string{
|
||||
"gzip@1.13-1 (arm64): /var/lib/dpkg/status, /var/lib/dpkg/status.d/gzip",
|
||||
},
|
||||
},
|
||||
{
|
||||
// covers packages only in status (ordinary Debian) and only in status.d (distroless)
|
||||
name: "status and status.d describing different packages are all kept",
|
||||
pkgs: []pkg.Package{
|
||||
dpkgTestPackage("apt", "1.8.2", "amd64", status),
|
||||
dpkgTestPackage("dash", "0.5.8-2.4", "amd64", statusDir+"dash"),
|
||||
dpkgTestPackage("netbase", "5.4", "all", statusDir+"netbase"),
|
||||
},
|
||||
expected: []string{
|
||||
"apt@1.8.2 (amd64): /var/lib/dpkg/status",
|
||||
"dash@0.5.8-2.4 (amd64): /var/lib/dpkg/status.d/dash",
|
||||
"netbase@5.4 (all): /var/lib/dpkg/status.d/netbase",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "different versions are not merged",
|
||||
pkgs: []pkg.Package{
|
||||
dpkgTestPackage("gzip", "1.13-1", "arm64", status),
|
||||
dpkgTestPackage("gzip", "1.12-1", "arm64", statusDir+"gzip"),
|
||||
},
|
||||
expected: []string{
|
||||
"gzip@1.12-1 (arm64): /var/lib/dpkg/status.d/gzip",
|
||||
"gzip@1.13-1 (arm64): /var/lib/dpkg/status",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "different architectures are not merged",
|
||||
pkgs: []pkg.Package{
|
||||
dpkgTestPackage("gzip", "1.13-1", "arm64", status),
|
||||
dpkgTestPackage("gzip", "1.13-1", "amd64", statusDir+"gzip"),
|
||||
},
|
||||
expected: []string{
|
||||
"gzip@1.13-1 (amd64): /var/lib/dpkg/status.d/gzip",
|
||||
"gzip@1.13-1 (arm64): /var/lib/dpkg/status",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "different dpkg directories are not merged",
|
||||
pkgs: []pkg.Package{
|
||||
dpkgTestPackage("gzip", "1.13-1", "arm64", "/usr/lib/dpkg/status"),
|
||||
dpkgTestPackage("gzip", "1.13-1", "arm64", statusDir+"gzip"),
|
||||
},
|
||||
expected: []string{
|
||||
"gzip@1.13-1 (arm64): /usr/lib/dpkg/status",
|
||||
"gzip@1.13-1 (arm64): /var/lib/dpkg/status.d/gzip",
|
||||
},
|
||||
},
|
||||
{
|
||||
// opkg shares this cataloger and metadata type, and describes each package in both its status file and
|
||||
// an info/<name>.control file. Those are not a status.d directory, so they are out of scope here.
|
||||
name: "an opkg status entry and its info control file are not merged",
|
||||
pkgs: []pkg.Package{
|
||||
dpkgTestPackage("gzip", "1.13-1", "arm64", "/usr/lib/opkg/status"),
|
||||
dpkgTestPackage("gzip", "1.13-1", "arm64", "/usr/lib/opkg/info/gzip.control"),
|
||||
},
|
||||
expected: []string{
|
||||
"gzip@1.13-1 (arm64): /usr/lib/opkg/info/gzip.control",
|
||||
"gzip@1.13-1 (arm64): /usr/lib/opkg/status",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
inputErr := errors.New("passed through")
|
||||
// relationships that do not involve a merged package are kept as they are
|
||||
inputRels := []artifact.Relationship{{
|
||||
From: file.Coordinates{RealPath: "/a"},
|
||||
To: file.Coordinates{RealPath: "/b"},
|
||||
Type: artifact.ContainsRelationship,
|
||||
}}
|
||||
|
||||
pkgs, rels, err := mergeStatusDirDuplicates(tt.pkgs, inputRels, inputErr)
|
||||
|
||||
assert.Equal(t, inputErr, err)
|
||||
assert.Equal(t, inputRels, rels)
|
||||
|
||||
var got []string
|
||||
ids := make(map[artifact.ID]struct{})
|
||||
for _, p := range pkgs {
|
||||
got = append(got, describe(p))
|
||||
ids[p.ID()] = struct{}{}
|
||||
}
|
||||
sort.Strings(got)
|
||||
|
||||
assert.Equal(t, tt.expected, got)
|
||||
assert.Len(t, ids, len(pkgs), "every package should have a distinct ID")
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_mergeStatusDirDuplicates_mergedPackageID(t *testing.T) {
|
||||
fromStatus := dpkgTestPackage("gzip", "1.13-1", "arm64", "/var/lib/dpkg/status")
|
||||
fromStatusDir := dpkgTestPackage("gzip", "1.13-1", "arm64", "/var/lib/dpkg/status.d/gzip")
|
||||
|
||||
got, _, err := mergeStatusDirDuplicates([]pkg.Package{fromStatus, fromStatusDir}, nil, nil)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, got, 1)
|
||||
|
||||
// the ID covers locations, so it matches neither input...
|
||||
assert.NotEqual(t, fromStatus.ID(), got[0].ID())
|
||||
assert.NotEqual(t, fromStatusDir.ID(), got[0].ID())
|
||||
|
||||
// ...but the ID of a package found with both locations to begin with
|
||||
expected := dpkgTestPackage("gzip", "1.13-1", "arm64", "/var/lib/dpkg/status", "/var/lib/dpkg/status.d/gzip")
|
||||
assert.Equal(t, expected.ID(), got[0].ID())
|
||||
}
|
||||
|
||||
func Test_mergeStatusDirDuplicates_inputsAreNotModified(t *testing.T) {
|
||||
fromStatus := dpkgTestPackage("gzip", "1.13-1", "arm64", "/var/lib/dpkg/status")
|
||||
fromStatusDir := dpkgTestPackage("gzip", "1.13-1", "arm64", "/var/lib/dpkg/status.d/gzip", "/usr/share/doc/gzip/copyright")
|
||||
|
||||
got, _, err := mergeStatusDirDuplicates([]pkg.Package{fromStatusDir, fromStatus}, nil, nil)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, got, 1)
|
||||
|
||||
// annotations are a map, so a change to the merged package must not reach the packages it was built from
|
||||
for _, l := range got[0].Locations.ToSlice() {
|
||||
l.Annotations["changed"] = "true"
|
||||
}
|
||||
|
||||
assert.Equal(t, []string{"/var/lib/dpkg/status"}, locationPaths(fromStatus))
|
||||
assert.Equal(t, []string{"/var/lib/dpkg/status.d/gzip"}, evidencePaths(fromStatusDir, pkg.PrimaryEvidenceAnnotation))
|
||||
for _, input := range []pkg.Package{fromStatus, fromStatusDir} {
|
||||
for _, l := range input.Locations.ToSlice() {
|
||||
assert.NotContains(t, l.Annotations, "changed", l.RealPath)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// the status file is the primary evidence of a merged package and the status.d file supporting evidence. The one
|
||||
// exception is a scan that tracks which files are hidden by later layers: it drops packages that have no visible
|
||||
// primary evidence, so a visible status.d file stays primary when the status entry is hidden.
|
||||
func Test_mergeStatusDirDuplicates_evidence(t *testing.T) {
|
||||
withVisibility := func(p pkg.Package, visibility string) pkg.Package {
|
||||
locations := file.NewLocationSet()
|
||||
for _, l := range p.Locations.ToSlice() {
|
||||
locations.Add(l.WithAnnotation(file.VisibleAnnotationKey, visibility))
|
||||
}
|
||||
p.Locations = locations
|
||||
p.SetID()
|
||||
return p
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
statusVisibility string
|
||||
statusDirVisibility string
|
||||
expectedPrimary []string
|
||||
expectedSupporting []string
|
||||
}{
|
||||
{
|
||||
name: "visibility is not tracked",
|
||||
expectedPrimary: []string{"/var/lib/dpkg/status"},
|
||||
expectedSupporting: []string{"/var/lib/dpkg/info/gzip.md5sums", "/var/lib/dpkg/status.d/gzip"},
|
||||
},
|
||||
{
|
||||
name: "visible status entry",
|
||||
statusVisibility: file.VisibleAnnotation,
|
||||
statusDirVisibility: file.VisibleAnnotation,
|
||||
expectedPrimary: []string{"/var/lib/dpkg/status"},
|
||||
expectedSupporting: []string{"/var/lib/dpkg/info/gzip.md5sums", "/var/lib/dpkg/status.d/gzip"},
|
||||
},
|
||||
{
|
||||
name: "hidden status entry",
|
||||
statusVisibility: file.HiddenAnnotation,
|
||||
statusDirVisibility: file.VisibleAnnotation,
|
||||
expectedPrimary: []string{"/var/lib/dpkg/status", "/var/lib/dpkg/status.d/gzip"},
|
||||
expectedSupporting: []string{"/var/lib/dpkg/info/gzip.md5sums"},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got, _, err := mergeStatusDirDuplicates([]pkg.Package{
|
||||
withVisibility(dpkgTestPackage("gzip", "1.13-1", "arm64", "/var/lib/dpkg/status.d/gzip"), tt.statusDirVisibility),
|
||||
withVisibility(dpkgTestPackage("gzip", "1.13-1", "arm64", "/var/lib/dpkg/status", "/var/lib/dpkg/info/gzip.md5sums"), tt.statusVisibility),
|
||||
}, nil, nil)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, got, 1)
|
||||
|
||||
assert.Equal(t, tt.expectedPrimary, evidencePaths(got[0], pkg.PrimaryEvidenceAnnotation))
|
||||
assert.Equal(t, tt.expectedSupporting, evidencePaths(got[0], pkg.SupportingEvidenceAnnotation))
|
||||
|
||||
if tt.statusDirVisibility == "" {
|
||||
return
|
||||
}
|
||||
var visiblePrimary bool
|
||||
for _, l := range got[0].Locations.ToSlice() {
|
||||
if l.Annotations[pkg.EvidenceAnnotationKey] == pkg.PrimaryEvidenceAnnotation && isVisible(l) {
|
||||
visiblePrimary = true
|
||||
}
|
||||
}
|
||||
assert.True(t, visiblePrimary, "the merged package needs visible primary evidence to be kept")
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_mergeStatusDirDuplicates_fileListing(t *testing.T) {
|
||||
record := func(p string) pkg.DpkgFileRecord {
|
||||
return pkg.DpkgFileRecord{Path: p, Digest: &file.Digest{Algorithm: "md5", Value: "d41d8cd98f00b204e9800998ecf8427e"}}
|
||||
}
|
||||
withFiles := func(p pkg.Package, files ...pkg.DpkgFileRecord) pkg.Package {
|
||||
entry := p.Metadata.(pkg.DpkgDBEntry)
|
||||
entry.Files = files
|
||||
p.Metadata = entry
|
||||
p.SetID()
|
||||
return p
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
statusFiles []pkg.DpkgFileRecord
|
||||
statusDFiles []pkg.DpkgFileRecord
|
||||
expectedPaths []string
|
||||
}{
|
||||
{
|
||||
name: "listing only beside the status.d file is kept",
|
||||
statusDFiles: []pkg.DpkgFileRecord{record("/usr/bin/gzip"), record("/usr/bin/gunzip")},
|
||||
expectedPaths: []string{"/usr/bin/gunzip", "/usr/bin/gzip"},
|
||||
},
|
||||
{
|
||||
name: "listing only beside the status file is kept",
|
||||
statusFiles: []pkg.DpkgFileRecord{record("/usr/bin/gzip")},
|
||||
expectedPaths: []string{"/usr/bin/gzip"},
|
||||
},
|
||||
{
|
||||
name: "listings are combined without repeating a path",
|
||||
statusFiles: []pkg.DpkgFileRecord{record("/usr/bin/gzip"), record("/usr/bin/zcat")},
|
||||
statusDFiles: []pkg.DpkgFileRecord{record("/usr/bin/gunzip"), record("/usr/bin/gzip")},
|
||||
expectedPaths: []string{"/usr/bin/gunzip", "/usr/bin/gzip", "/usr/bin/zcat"},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got, _, err := mergeStatusDirDuplicates([]pkg.Package{
|
||||
withFiles(dpkgTestPackage("gzip", "1.13-1", "arm64", "/var/lib/dpkg/status.d/gzip"), tt.statusDFiles...),
|
||||
withFiles(dpkgTestPackage("gzip", "1.13-1", "arm64", "/var/lib/dpkg/status"), tt.statusFiles...),
|
||||
}, nil, nil)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, got, 1)
|
||||
|
||||
var paths []string
|
||||
for _, f := range got[0].Metadata.(pkg.DpkgDBEntry).Files {
|
||||
paths = append(paths, f.Path)
|
||||
}
|
||||
assert.Equal(t, tt.expectedPaths, paths)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_mergeStatusDirDuplicates_licenses(t *testing.T) {
|
||||
ctx := context.TODO()
|
||||
fromStatus := dpkgTestPackage("gzip", "1.13-1", "arm64", "/var/lib/dpkg/status")
|
||||
fromStatus.Licenses = pkg.NewLicenseSet(pkg.NewLicenseWithContext(ctx, "GPL-3.0-or-later"))
|
||||
fromStatus.SetID()
|
||||
fromStatusDir := dpkgTestPackage("gzip", "1.13-1", "arm64", "/var/lib/dpkg/status.d/gzip")
|
||||
fromStatusDir.Licenses = pkg.NewLicenseSet(pkg.NewLicenseWithContext(ctx, "FSFAP"))
|
||||
fromStatusDir.SetID()
|
||||
|
||||
got, _, err := mergeStatusDirDuplicates([]pkg.Package{fromStatus, fromStatusDir}, nil, nil)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, got, 1)
|
||||
|
||||
var values []string
|
||||
for _, l := range got[0].Licenses.ToSlice() {
|
||||
values = append(values, l.Value)
|
||||
}
|
||||
sort.Strings(values)
|
||||
assert.Equal(t, []string{"FSFAP", "GPL-3.0-or-later"}, values)
|
||||
}
|
||||
|
||||
// a dpkg database within an archive has the archive as its real path, so the path within the archive is what
|
||||
// identifies the database directory.
|
||||
func Test_mergeStatusDirDuplicates_withinArchive(t *testing.T) {
|
||||
nested := func(archive, entry string) file.Location {
|
||||
return file.NewLocationFromCoordinates(file.Coordinates{
|
||||
RealPath: archive,
|
||||
FullPath: archive + file.ArchivePathSeparator + entry,
|
||||
})
|
||||
}
|
||||
fullPaths := func(p pkg.Package) []string {
|
||||
var paths []string
|
||||
for _, l := range p.Locations.ToSlice() {
|
||||
paths = append(paths, l.FullNestedPath())
|
||||
}
|
||||
sort.Strings(paths)
|
||||
return paths
|
||||
}
|
||||
|
||||
t.Run("same archive", func(t *testing.T) {
|
||||
got, _, err := mergeStatusDirDuplicates([]pkg.Package{
|
||||
dpkgTestPackageAt("gzip", "1.13-1", "arm64", nested("/rootfs.tar", "var/lib/dpkg/status")),
|
||||
dpkgTestPackageAt("gzip", "1.13-1", "arm64", nested("/rootfs.tar", "var/lib/dpkg/status.d/gzip")),
|
||||
}, nil, nil)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, got, 1)
|
||||
assert.Equal(t, []string{
|
||||
"/rootfs.tar!/var/lib/dpkg/status",
|
||||
"/rootfs.tar!/var/lib/dpkg/status.d/gzip",
|
||||
}, fullPaths(got[0]))
|
||||
})
|
||||
|
||||
t.Run("different archives", func(t *testing.T) {
|
||||
got, _, err := mergeStatusDirDuplicates([]pkg.Package{
|
||||
dpkgTestPackageAt("gzip", "1.13-1", "arm64", nested("/one.tar", "var/lib/dpkg/status")),
|
||||
dpkgTestPackageAt("gzip", "1.13-1", "arm64", nested("/two.tar", "var/lib/dpkg/status.d/gzip")),
|
||||
}, nil, nil)
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, got, 2)
|
||||
})
|
||||
|
||||
t.Run("archive and the filesystem around it", func(t *testing.T) {
|
||||
got, _, err := mergeStatusDirDuplicates([]pkg.Package{
|
||||
dpkgTestPackage("gzip", "1.13-1", "arm64", "/var/lib/dpkg/status"),
|
||||
dpkgTestPackageAt("gzip", "1.13-1", "arm64", nested("/rootfs.tar", "var/lib/dpkg/status.d/gzip")),
|
||||
}, nil, nil)
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, got, 2)
|
||||
})
|
||||
}
|
||||
|
||||
// when several layers are cataloged the status file is seen once per layer, as a package per layer that share an ID
|
||||
// and collapse into one downstream. The merge must keep that true.
|
||||
func Test_mergeStatusDirDuplicates_statusInSeveralLayers(t *testing.T) {
|
||||
statusInLayer := func(layer string) pkg.Package {
|
||||
return dpkgTestPackageAt("gzip", "1.13-1", "arm64",
|
||||
file.NewLocationFromCoordinates(file.Coordinates{RealPath: "/var/lib/dpkg/status", FileSystemID: layer}))
|
||||
}
|
||||
lower, upper := statusInLayer("sha256:lower"), statusInLayer("sha256:upper")
|
||||
require.Equal(t, lower.ID(), upper.ID(), "the same status entry in two layers shares an ID before merging")
|
||||
|
||||
got, _, err := mergeStatusDirDuplicates([]pkg.Package{
|
||||
lower,
|
||||
dpkgTestPackage("gzip", "1.13-1", "arm64", "/var/lib/dpkg/status.d/gzip"),
|
||||
upper,
|
||||
}, nil, nil)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Len(t, got, 2, "one package per layer the status file was seen in")
|
||||
assert.Equal(t, got[0].ID(), got[1].ID(), "both must still collapse into one package downstream")
|
||||
for _, p := range got {
|
||||
assert.Equal(t, []string{"/var/lib/dpkg/status", "/var/lib/dpkg/status.d/gzip"}, locationPaths(p))
|
||||
}
|
||||
}
|
||||
|
||||
// the fixture holds verbatim records from a Docker Hardened Images Debian 13 image, which lists every installed
|
||||
// package in both /var/lib/dpkg/status and /var/lib/dpkg/status.d/<name>. The fixture arranges them so that gzip is
|
||||
// in both, libc6 (which gzip depends on) is only in status, and bzip2 is only in status.d.
|
||||
func TestDpkgCataloger_statusAndStatusDir(t *testing.T) {
|
||||
pkgtest.NewCatalogTester().
|
||||
FromDirectory(t, "testdata/status-and-status-d").
|
||||
WithErrorAssertion(require.NoError).
|
||||
ExpectsAssertion(func(t *testing.T, pkgs []pkg.Package, relationships []artifact.Relationship) {
|
||||
got := make(map[string][]string)
|
||||
byName := make(map[string]pkg.Package)
|
||||
for _, p := range pkgs {
|
||||
key := p.Name + "@" + p.Version
|
||||
require.NotContains(t, got, key, "package reported more than once")
|
||||
got[key] = locationPaths(p)
|
||||
byName[p.Name] = p
|
||||
}
|
||||
|
||||
assert.Equal(t, map[string][]string{
|
||||
"gzip@1.13-1+dhi1": {
|
||||
"var/lib/dpkg/info/gzip.md5sums",
|
||||
"var/lib/dpkg/status",
|
||||
"var/lib/dpkg/status.d/gzip",
|
||||
},
|
||||
"libc6@2.41-12+deb13u3+dhi1": {"var/lib/dpkg/status"},
|
||||
"bzip2@1.0.8-6+dhi2": {"var/lib/dpkg/status.d/bzip2"},
|
||||
}, got)
|
||||
|
||||
gzip := byName["gzip"]
|
||||
entry, ok := gzip.Metadata.(pkg.DpkgDBEntry)
|
||||
require.True(t, ok)
|
||||
assert.NotEmpty(t, entry.Files, "the merged package keeps the file listing found beside the status file")
|
||||
assert.Equal(t, []string{"var/lib/dpkg/status"}, evidencePaths(gzip, pkg.PrimaryEvidenceAnnotation))
|
||||
assert.Contains(t, evidencePaths(gzip, pkg.SupportingEvidenceAnnotation), "var/lib/dpkg/status.d/gzip")
|
||||
|
||||
// dependencies are resolved after the merge, so the dependency of gzip on libc6 is reported once and
|
||||
// points at the merged package
|
||||
var dependencies []string
|
||||
for _, r := range relationships {
|
||||
if r.Type != artifact.DependencyOfRelationship {
|
||||
continue
|
||||
}
|
||||
from, to := r.From.(pkg.Package), r.To.(pkg.Package)
|
||||
dependencies = append(dependencies, from.Name+" -> "+to.Name)
|
||||
if to.Name == "gzip" {
|
||||
assert.Equal(t, gzip.ID(), to.ID())
|
||||
}
|
||||
}
|
||||
sort.Strings(dependencies)
|
||||
assert.Equal(t, []string{"libc6 -> bzip2", "libc6 -> gzip"}, dependencies)
|
||||
}).
|
||||
TestCataloger(t, NewDBCataloger())
|
||||
}
|
||||
|
||||
// when several layers are cataloged, an older copy of the status file is hidden and the newest is visible. All copies
|
||||
// share an ID and collapse downstream, where the first annotation seen for a location wins. So every copy must agree
|
||||
// on the evidence of the status.d location, or the merged result depends on parse completion order.
|
||||
func Test_mergeStatusDirDuplicates_evidenceAgreesAcrossLayers(t *testing.T) {
|
||||
at := func(realPath, layer, visibility string) file.Location {
|
||||
return file.NewLocationFromCoordinates(file.Coordinates{RealPath: realPath, FileSystemID: layer}).
|
||||
WithAnnotation(file.VisibleAnnotationKey, visibility)
|
||||
}
|
||||
lower := dpkgTestPackageAt("gzip", "1.13-1", "arm64", at("/var/lib/dpkg/status", "sha256:lower", file.HiddenAnnotation))
|
||||
upper := dpkgTestPackageAt("gzip", "1.13-1", "arm64", at("/var/lib/dpkg/status", "sha256:upper", file.VisibleAnnotation))
|
||||
statusDir := dpkgTestPackageAt("gzip", "1.13-1", "arm64", at("/var/lib/dpkg/status.d/gzip", "sha256:base", file.VisibleAnnotation))
|
||||
|
||||
got, _, err := mergeStatusDirDuplicates([]pkg.Package{lower, statusDir, upper}, nil, nil)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, got, 2)
|
||||
require.Equal(t, got[0].ID(), got[1].ID())
|
||||
|
||||
// a visible status entry exists, so status.d is supporting on every copy
|
||||
for i, p := range got {
|
||||
assert.Equal(t, []string{"/var/lib/dpkg/status.d/gzip"}, evidencePaths(p, pkg.SupportingEvidenceAnnotation), "status copy %d", i)
|
||||
}
|
||||
}
|
||||
|
||||
// the same status.d entry seen in two layers is folded into one status entry. Which copy's file records win must not
|
||||
// depend on map iteration order.
|
||||
func Test_mergeStatusDirDuplicates_deterministicAcrossStatusDirCopies(t *testing.T) {
|
||||
statusDirInLayer := func(layer, digest string) pkg.Package {
|
||||
p := dpkgTestPackageAt("gzip", "1.13-1", "arm64",
|
||||
file.NewLocationFromCoordinates(file.Coordinates{RealPath: "/var/lib/dpkg/status.d/gzip", FileSystemID: layer}))
|
||||
m := p.Metadata.(pkg.DpkgDBEntry)
|
||||
m.Files = []pkg.DpkgFileRecord{{Path: "/bin/gzip", Digest: &file.Digest{Algorithm: "md5", Value: digest}}}
|
||||
p.Metadata = m
|
||||
p.SetID()
|
||||
return p
|
||||
}
|
||||
input := func() []pkg.Package {
|
||||
return []pkg.Package{
|
||||
dpkgTestPackage("gzip", "1.13-1", "arm64", "/var/lib/dpkg/status"),
|
||||
statusDirInLayer("sha256:lower", "aaaa"),
|
||||
statusDirInLayer("sha256:upper", "bbbb"),
|
||||
}
|
||||
}
|
||||
|
||||
first, _, err := mergeStatusDirDuplicates(input(), nil, nil)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, first, 1)
|
||||
|
||||
for i := 0; i < 50; i++ {
|
||||
got, _, err := mergeStatusDirDuplicates(input(), nil, nil)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, got, 1)
|
||||
require.Equal(t, first[0].Metadata, got[0].Metadata, "run %d", i)
|
||||
require.Equal(t, first[0].ID(), got[0].ID(), "run %d", i)
|
||||
}
|
||||
}
|
||||
|
||||
// the merge drops status.d packages and changes the ID of the status packages it folds them into, so relationships
|
||||
// handed to it must be rewritten to the surviving packages rather than left pointing at IDs that no longer exist.
|
||||
func Test_mergeStatusDirDuplicates_relationshipsFollowMergedPackages(t *testing.T) {
|
||||
fromStatus := dpkgTestPackage("gzip", "1.13-1", "arm64", "/var/lib/dpkg/status")
|
||||
fromStatusDir := dpkgTestPackage("gzip", "1.13-1", "arm64", "/var/lib/dpkg/status.d/gzip")
|
||||
libc := dpkgTestPackage("libc6", "2.41-12", "arm64", "/var/lib/dpkg/status")
|
||||
|
||||
rels := []artifact.Relationship{
|
||||
{From: libc, To: fromStatus, Type: artifact.DependencyOfRelationship},
|
||||
{From: libc, To: fromStatusDir, Type: artifact.DependencyOfRelationship},
|
||||
}
|
||||
|
||||
got, gotRels, err := mergeStatusDirDuplicates([]pkg.Package{fromStatus, fromStatusDir, libc}, rels, nil)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, got, 2)
|
||||
|
||||
ids := make(map[artifact.ID]bool)
|
||||
for _, p := range got {
|
||||
ids[p.ID()] = true
|
||||
}
|
||||
require.NotEmpty(t, gotRels)
|
||||
for _, r := range gotRels {
|
||||
assert.True(t, ids[r.From.ID()], "relationship from %s points at a package that was not returned", r.From.ID())
|
||||
assert.True(t, ids[r.To.ID()], "relationship to %s points at a package that was not returned", r.To.ID())
|
||||
}
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
c5e447de172a08388bf7c3f1f921aaf0 usr/bin/gunzip
|
||||
2b8a2f0a469a41591c5b76d04851a3ef usr/bin/gzexe
|
||||
2e2a9ac334d8dd7d71186420eeb64488 usr/bin/gzip
|
||||
fa5318f2617d9496214e1f3f2b4f8057 usr/bin/zcat
|
||||
6b186899077092c32be333b7dcc70baf usr/bin/zcmp
|
||||
0877a3ce43699c600f530a76bf9af1fd usr/bin/zdiff
|
||||
00a56ed99986d72fd5967de74d69470c usr/bin/zegrep
|
||||
997a6cfb1a2b3f88160ffa320d29d735 usr/bin/zfgrep
|
||||
6a9128ea5527cabc743ce7a6af349ad1 usr/bin/zforce
|
||||
99a7363f2882018ba6d91741757cc5a3 usr/bin/zgrep
|
||||
de2db924a63b003fb83a0a2553e903e4 usr/bin/zless
|
||||
1be17ef267e4cc49755fa2a5475a831e usr/bin/zmore
|
||||
b91567e8108e21fb2079820028d15f94 usr/bin/znew
|
||||
0aba16f865e2de42720f93a0c6daae3a usr/share/doc/gzip/NEWS.gz
|
||||
17110c76257cb1011462e852bcb6a258 usr/share/doc/gzip/README.gz
|
||||
e9a8044c3c24d98caad5dcc3ac799e33 usr/share/doc/gzip/TODO
|
||||
f50beaa8bc48df21ab7c5852ae189144 usr/share/doc/gzip/changelog.Debian.gz
|
||||
a58e1b883152732e447499336ad6a586 usr/share/doc/gzip/changelog.gz
|
||||
8208bf9a2beb11099ca9d84553f53d65 usr/share/doc/gzip/copyright
|
||||
6b296b354b25f16aeb7824ec40a77bb7 usr/share/info/gzip.info.gz
|
||||
171c50cf652e2516b92ea07e26abebc9 usr/share/man/man1/gzexe.1.gz
|
||||
28b069108297d3da6ae0981332c05664 usr/share/man/man1/gzip.1.gz
|
||||
c6f9e6e3a3141d815e359544992543b5 usr/share/man/man1/zdiff.1.gz
|
||||
d7d7b5db46c9ff51e80c6ccbde54d37f usr/share/man/man1/zforce.1.gz
|
||||
fea039ae5b48e08831b129560ffd4b4e usr/share/man/man1/zgrep.1.gz
|
||||
f6de1ebc9404459a75efce5c24e0f316 usr/share/man/man1/zless.1.gz
|
||||
8177ea9aa9e26c191428d8575c56d1b0 usr/share/man/man1/zmore.1.gz
|
||||
5146e40980535083365ed032b1d2b671 usr/share/man/man1/znew.1.gz
|
||||
@@ -0,0 +1,39 @@
|
||||
Package: gzip
|
||||
Status: install ok installed
|
||||
Version: 1.13-1+dhi1
|
||||
Architecture: arm64
|
||||
Essential: yes
|
||||
Maintainer: Docker Hardened Images <dhi@docker.com>
|
||||
Installed-Size: 287
|
||||
Pre-Depends: libc6 (>= 2.41)
|
||||
Suggests: less
|
||||
Conflicts: zutils (<< 1.13-2~)
|
||||
Section: utils
|
||||
Priority: required
|
||||
Homepage: https://www.gnu.org/software/gzip/
|
||||
Description: GNU compression utilities
|
||||
This package provides the standard GNU file compression utilities, which
|
||||
are also the default compression tools for Debian. They typically operate
|
||||
on files with names ending in '.gz', but can also decompress files ending
|
||||
in '.Z' created with 'compress'.
|
||||
|
||||
Package: libc6
|
||||
Status: install ok installed
|
||||
Source: glibc
|
||||
Version: 2.41-12+deb13u3+dhi1
|
||||
Architecture: arm64
|
||||
Maintainer: Docker Hardened Images <dhi@docker.com>
|
||||
Installed-Size: 23769
|
||||
Depends: libgcc-s1
|
||||
Recommends: libidn2-0 (>= 2.0.5~)
|
||||
Suggests: glibc-doc, debconf | debconf-2.0, libc-l10n, locales, libnss-nis, libnss-nisplus
|
||||
Breaks: base-files (<< 13.3~), chrony (<< 4.2-3~), dhcpcd (<< 1:10.1.0-7~), fakechroot (<< 2.19-3.5), firefox (<< 91~), firefox-esr (<< 91~), gnumach-image-1.8-486 (<< 2:1.8+git20210923~), gnumach-image-1.8-486-dbg (<< 2:1.8+git20210923~), gnumach-image-1.8-xen-486 (<< 2:1.8+git20210923~), gnumach-image-1.8-xen-486-dbg (<< 2:1.8+git20210923~), hurd (<< 1:0.9.git20220301-2), libamdhip64-5 (<< 5.7.1-5+b1), libhiprtc-builtins5 (<< 5.7.1-5+b1), librccl1 (<< 5.4.3-3+b1), libswupdate0.1 (<< 2024.12.1+dfsg-1+b3), locales (<< 2.41), locales-all (<< 2.41), lua-swupdate (<< 2024.12.1+dfsg-1+b3), nscd (<< 2.41), pd-scaf (<< 1:0.14.1+darcs20180201-6+b4), postgresql-15-pllua (<< 1:2.0.12-4), postgresql-17-pllua (<< 1:2.0.12-3+b2), python3-iptables (<< 1.0.0-2), python3-mrgingham (<< 1.25-1), python3-onnxruntime (<< 1.20.1+dfsg-2~), sysvinit (<< 3.09-2~), sysvinit-core (<< 3.09-2~), tinydns (<< 1:1.05-14), uwsgi-plugin-pypy3 (<< 0.0.2+b1), valgrind (<< 1:3.19.0-1~)
|
||||
Section: libs
|
||||
Priority: optional
|
||||
Multi-Arch: same
|
||||
Homepage: https://www.gnu.org/software/libc/libc.html
|
||||
Description: GNU C Library: Shared libraries
|
||||
Contains the standard libraries that are used by nearly all programs on
|
||||
the system. This package includes shared versions of the standard C library
|
||||
and the standard math library, as well as many others.
|
||||
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
Package: bzip2
|
||||
Version: 1.0.8-6+dhi2
|
||||
Architecture: arm64
|
||||
Maintainer: Docker Hardened Images <dhi@docker.com>
|
||||
Installed-Size: 193
|
||||
Depends: libbz2-1.0 (= 1.0.8-6+dhi2), libc6 (>= 2.41)
|
||||
Suggests: bzip2-doc
|
||||
Replaces: libbz2 (<< 0.9.5d-3)
|
||||
Section: utils
|
||||
Priority: standard
|
||||
Multi-Arch: foreign
|
||||
Homepage: https://sourceware.org/bzip2/
|
||||
Description: high-quality block-sorting file compressor - utilities
|
||||
bzip2 is a freely available, patent free, data compressor.
|
||||
.
|
||||
bzip2 compresses files using the Burrows-Wheeler block-sorting text
|
||||
compression algorithm, and Huffman coding. Compression is generally
|
||||
considerably better than that achieved by more conventional
|
||||
LZ77/LZ78-based compressors, and approaches the performance of the PPM
|
||||
family of statistical compressors.
|
||||
.
|
||||
The archive file format of bzip2 (.bz2) is incompatible with that of its
|
||||
predecessor, bzip (.bz).
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
Package: gzip
|
||||
Version: 1.13-1+dhi1
|
||||
Architecture: arm64
|
||||
Essential: yes
|
||||
Maintainer: Docker Hardened Images <dhi@docker.com>
|
||||
Installed-Size: 287
|
||||
Pre-Depends: libc6 (>= 2.41)
|
||||
Suggests: less
|
||||
Conflicts: zutils (<< 1.13-2~)
|
||||
Section: utils
|
||||
Priority: required
|
||||
Homepage: https://www.gnu.org/software/gzip/
|
||||
Description: GNU compression utilities
|
||||
This package provides the standard GNU file compression utilities, which
|
||||
are also the default compression tools for Debian. They typically operate
|
||||
on files with names ending in '.gz', but can also decompress files ending
|
||||
in '.Z' created with 'compress'.
|
||||
@@ -191,16 +191,20 @@ func (c *Cataloger) Catalog(ctx context.Context, resolver file.Resolver) ([]pkg.
|
||||
|
||||
lgr := log.Nested("cataloger", c.upstreamCataloger)
|
||||
|
||||
env := Environment{
|
||||
requests := c.selectFiles(resolver)
|
||||
|
||||
var env Environment
|
||||
if len(requests) > 0 {
|
||||
// The release is only needed by parsers, so skip identifying it when there is nothing to parse.
|
||||
// TODO: consider passing into the cataloger, this would affect the cataloger interface (and all implementations). This can be deferred until later.
|
||||
LinuxRelease: linux.IdentifyRelease(resolver),
|
||||
env.LinuxRelease = linux.IdentifyRelease(resolver)
|
||||
}
|
||||
|
||||
type result struct {
|
||||
pkgs []pkg.Package
|
||||
rels []artifact.Relationship
|
||||
}
|
||||
errs := sync.Collect(&ctx, cataloging.ExecutorFile, sync.ToSeq(c.selectFiles(resolver)), func(req request) (result, error) {
|
||||
errs := sync.Collect(&ctx, cataloging.ExecutorFile, sync.ToSeq(requests), func(req request) (result, error) {
|
||||
location, parser := req.Location, req.Parser
|
||||
|
||||
log.WithFields("path", location.FullNestedPath()).Trace("parsing file contents")
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
package generic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/anchore/syft/syft/artifact"
|
||||
"github.com/anchore/syft/syft/file"
|
||||
"github.com/anchore/syft/syft/pkg"
|
||||
)
|
||||
|
||||
// releaseLookupCountingResolver records how many times the cataloger asks for /etc/os-release,
|
||||
// the first file linux.IdentifyRelease looks up.
|
||||
type releaseLookupCountingResolver struct {
|
||||
file.Resolver
|
||||
osReleaseLookups int
|
||||
}
|
||||
|
||||
func (r *releaseLookupCountingResolver) FilesByPath(paths ...string) ([]file.Location, error) {
|
||||
for _, p := range paths {
|
||||
if p == "/etc/os-release" {
|
||||
r.osReleaseLookups++
|
||||
}
|
||||
}
|
||||
return r.Resolver.FilesByPath(paths...)
|
||||
}
|
||||
|
||||
func Test_Cataloger_SkipsOSReleaseWhenNoFilesMatch(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
files []string // what the resolver holds; the cataloger globs for **/a-path.txt
|
||||
wantReadOSRelease bool
|
||||
}{
|
||||
{
|
||||
name: "no files",
|
||||
files: nil,
|
||||
wantReadOSRelease: false,
|
||||
},
|
||||
{
|
||||
name: "files, but none match the glob",
|
||||
files: []string{"testdata/another-path.txt"},
|
||||
wantReadOSRelease: false,
|
||||
},
|
||||
{
|
||||
name: "a file matches the glob",
|
||||
files: []string{"testdata/a-path.txt"},
|
||||
wantReadOSRelease: true,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
parser := func(_ context.Context, _ file.Resolver, _ *Environment, _ file.LocationReadCloser) ([]pkg.Package, []artifact.Relationship, error) {
|
||||
return nil, nil, nil
|
||||
}
|
||||
resolver := &releaseLookupCountingResolver{Resolver: file.NewMockResolverForPaths(tt.files...)}
|
||||
|
||||
_, _, err := NewCataloger("test-cataloger").WithParserByGlobs(parser, "**/a-path.txt").Catalog(context.Background(), resolver)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, tt.wantReadOSRelease, resolver.osReleaseLookups > 0, "os-release lookups: %d", resolver.osReleaseLookups)
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,7 @@ import (
|
||||
"github.com/anchore/syft/internal/archive"
|
||||
intFile "github.com/anchore/syft/internal/file"
|
||||
"github.com/anchore/syft/internal/log"
|
||||
"github.com/anchore/syft/internal/spdxlicense"
|
||||
"github.com/anchore/syft/internal/tmpdir"
|
||||
"github.com/anchore/syft/internal/unknown"
|
||||
"github.com/anchore/syft/syft/artifact"
|
||||
@@ -53,6 +54,8 @@ var archiveFormatGlobs = []string{
|
||||
"**/*.zap", // ZAP add-ons https://github.com/zaproxy/zaproxy/wiki/ZapAddOns
|
||||
}
|
||||
|
||||
const eclipseClasspathDualLicense = "EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0"
|
||||
|
||||
// javaArchiveHashes are all the current hash algorithms used to calculate archive digests
|
||||
var javaArchiveHashes = []crypto.Hash{
|
||||
crypto.SHA1,
|
||||
@@ -320,7 +323,7 @@ func (j *archiveParser) discoverMainPackage(ctx context.Context) (*pkg.Package,
|
||||
func (j *archiveParser) discoverNameVersionLicense(ctx context.Context, manifest *pkg.JavaManifest) (string, string, []pkg.License, *parsedPomProject) {
|
||||
// we use j.location because we want to associate the license declaration with where we discovered the contents in the manifest
|
||||
// TODO: when we support locations of paths within archives we should start passing the specific manifest location object instead of the top jar
|
||||
lics := pkg.NewLicensesFromLocationWithContext(ctx, j.location, selectLicenses(manifest)...)
|
||||
lics := combineEclipseClasspathAlternatives(pkg.NewLicensesFromLocationWithContext(ctx, j.location, selectLicenses(manifest)...))
|
||||
/*
|
||||
We should name and version from, in this order:
|
||||
1. pom.properties if we find exactly 1
|
||||
@@ -412,9 +415,90 @@ func toPkgLicenses(ctx context.Context, location *file.Location, licenses []mave
|
||||
if name == "" && url == "" {
|
||||
continue
|
||||
}
|
||||
out = append(out, pkg.NewLicenseFromFieldsWithContext(ctx, name, url, location))
|
||||
candidate := pkg.NewLicenseFromFieldsWithContext(ctx, name, url, location)
|
||||
out = append(out, candidate)
|
||||
}
|
||||
return combineMavenLicenseAlternatives(out)
|
||||
}
|
||||
|
||||
func combineMavenLicenseAlternatives(licenses []pkg.License) []pkg.License {
|
||||
if len(licenses) < 2 {
|
||||
return licenses
|
||||
}
|
||||
|
||||
enriched := slices.Clone(licenses)
|
||||
for i := range enriched {
|
||||
if enriched[i].SPDXExpression == "" && len(enriched[i].URLs) > 0 {
|
||||
if info, found := spdxlicense.LicenseByURL(enriched[i].URLs[0]); found {
|
||||
enriched[i].SPDXExpression = info.ID
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return combineLicenseAlternatives(enriched)
|
||||
}
|
||||
|
||||
func combineEclipseClasspathAlternatives(licenses []pkg.License) []pkg.License {
|
||||
if len(licenses) != 2 {
|
||||
return licenses
|
||||
}
|
||||
|
||||
hasEPL := false
|
||||
hasGPLClasspath := false
|
||||
for _, candidate := range licenses {
|
||||
switch candidate.SPDXExpression {
|
||||
case "EPL-2.0":
|
||||
hasEPL = true
|
||||
case "GPL-2.0-only WITH Classpath-exception-2.0":
|
||||
hasGPLClasspath = true
|
||||
}
|
||||
}
|
||||
if !hasEPL || !hasGPLClasspath {
|
||||
return licenses
|
||||
}
|
||||
|
||||
return combineLicenseAlternatives(licenses)
|
||||
}
|
||||
|
||||
func combineLicenseAlternatives(licenses []pkg.License) []pkg.License {
|
||||
if len(licenses) < 2 {
|
||||
return licenses
|
||||
}
|
||||
|
||||
var values []string
|
||||
var expressions []string
|
||||
var locations []file.Location
|
||||
urls := strset.New()
|
||||
seenExpressions := strset.New()
|
||||
|
||||
for _, candidate := range licenses {
|
||||
if candidate.SPDXExpression == "" {
|
||||
return licenses
|
||||
}
|
||||
|
||||
if candidate.Value != "" {
|
||||
values = append(values, candidate.Value)
|
||||
}
|
||||
if !seenExpressions.Has(candidate.SPDXExpression) {
|
||||
expressions = append(expressions, candidate.SPDXExpression)
|
||||
seenExpressions.Add(candidate.SPDXExpression)
|
||||
}
|
||||
urls.Add(candidate.URLs...)
|
||||
locations = append(locations, candidate.Locations.ToSlice()...)
|
||||
}
|
||||
|
||||
combinedURLs := urls.List()
|
||||
slices.Sort(combinedURLs)
|
||||
|
||||
return []pkg.License{
|
||||
{
|
||||
Value: strings.Join(values, " OR "),
|
||||
SPDXExpression: strings.Join(expressions, " OR "),
|
||||
Type: licenses[0].Type,
|
||||
URLs: combinedURLs,
|
||||
Locations: file.NewLocationSet(locations...),
|
||||
},
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
type parsedPomProject struct {
|
||||
@@ -623,6 +707,7 @@ func (j *archiveParser) getLicenseFromFileInArchive(ctx context.Context) []pkg.L
|
||||
licenseContents := contents[licenseMatch]
|
||||
r := strings.NewReader(licenseContents)
|
||||
foundLicenses := pkg.NewLicensesFromReadCloserWithContext(ctx, file.NewLocationReadCloser(j.location, io.NopCloser(r)))
|
||||
foundLicenses = normalizeClasspathExceptionLicenses(foundLicenses, licenseContents)
|
||||
for _, l := range foundLicenses {
|
||||
if l.SPDXExpression != "" {
|
||||
identified = append(identified, l)
|
||||
@@ -684,6 +769,35 @@ func (j *archiveParser) versionFromPropertiesFile(ctx context.Context, manifest
|
||||
return ""
|
||||
}
|
||||
|
||||
func normalizeClasspathExceptionLicenses(found []pkg.License, contents string) []pkg.License {
|
||||
if len(found) != 2 || !strings.Contains(strings.ToLower(contents), "classpath exception") {
|
||||
return found
|
||||
}
|
||||
|
||||
var epl *pkg.License
|
||||
var gpl *pkg.License
|
||||
for i := range found {
|
||||
switch found[i].SPDXExpression {
|
||||
case "EPL-2.0":
|
||||
epl = &found[i]
|
||||
case "GPL-2.0-only":
|
||||
gpl = &found[i]
|
||||
}
|
||||
}
|
||||
if epl == nil || gpl == nil {
|
||||
return found
|
||||
}
|
||||
|
||||
return []pkg.License{
|
||||
{
|
||||
Value: eclipseClasspathDualLicense,
|
||||
SPDXExpression: eclipseClasspathDualLicense,
|
||||
Type: epl.Type,
|
||||
Locations: file.NewLocationSet(append(epl.Locations.ToSlice(), gpl.Locations.ToSlice()...)...),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// discoverPkgsFromNestedArchives recurses into the java archives inside this one, which needs an
|
||||
// archive file to unzip; an already-extracted archive's nested archives are the archive cataloger
|
||||
// task's to find.
|
||||
|
||||
@@ -91,6 +91,83 @@ func TestSearchMavenForLicenses(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestToPkgLicensesCombinesMavenAlternatives(t *testing.T) {
|
||||
const eplName = "Eclipse Public License 2.0"
|
||||
const eplURL = "https://projects.eclipse.org/license/epl-2.0"
|
||||
const gplName = "GNU General Public License, version 2 with the GNU Classpath Exception"
|
||||
const gplURL = "https://projects.eclipse.org/license/secondary-gpl-2.0-cp"
|
||||
|
||||
actual := toPkgLicenses(pkgtest.Context(t), nil, []maven.License{
|
||||
{Name: ptr(eplName), URL: ptr(eplURL)},
|
||||
{Name: ptr(gplName), URL: ptr(gplURL)},
|
||||
})
|
||||
|
||||
expected := []pkg.License{
|
||||
{
|
||||
Value: eplName + " OR " + gplName,
|
||||
SPDXExpression: "EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0",
|
||||
Type: license.Declared,
|
||||
URLs: []string{eplURL, gplURL},
|
||||
},
|
||||
}
|
||||
assert.Equal(t, expected, actual)
|
||||
}
|
||||
|
||||
func TestCombineEclipseClasspathAlternatives(t *testing.T) {
|
||||
alternatives := []pkg.License{
|
||||
{Value: "EPL", SPDXExpression: "EPL-2.0", Type: license.Declared},
|
||||
{Value: "GPL plus exception", SPDXExpression: "GPL-2.0-only WITH Classpath-exception-2.0", Type: license.Declared},
|
||||
}
|
||||
|
||||
actual := combineEclipseClasspathAlternatives(alternatives)
|
||||
require.Len(t, actual, 1)
|
||||
assert.Equal(t, eclipseClasspathDualLicense, actual[0].SPDXExpression)
|
||||
|
||||
unrelated := []pkg.License{
|
||||
{SPDXExpression: "Apache-2.0"},
|
||||
{SPDXExpression: "MIT"},
|
||||
}
|
||||
assert.Equal(t, unrelated, combineEclipseClasspathAlternatives(unrelated))
|
||||
}
|
||||
|
||||
func TestNormalizeClasspathExceptionLicenses(t *testing.T) {
|
||||
location := file.NewLocation("META-INF/LICENSE.md")
|
||||
actual := normalizeClasspathExceptionLicenses([]pkg.License{
|
||||
{
|
||||
Value: "EPL-2.0",
|
||||
SPDXExpression: "EPL-2.0",
|
||||
Type: license.Concluded,
|
||||
Locations: file.NewLocationSet(location),
|
||||
},
|
||||
{
|
||||
Value: "GPL-2.0-only",
|
||||
SPDXExpression: "GPL-2.0-only",
|
||||
Type: license.Concluded,
|
||||
Locations: file.NewLocationSet(location),
|
||||
},
|
||||
}, "## CLASSPATH EXCEPTION\n\nAs a special exception...")
|
||||
|
||||
expected := []pkg.License{
|
||||
{
|
||||
Value: eclipseClasspathDualLicense,
|
||||
SPDXExpression: eclipseClasspathDualLicense,
|
||||
Type: license.Concluded,
|
||||
Locations: file.NewLocationSet(location),
|
||||
},
|
||||
}
|
||||
assert.Equal(t, expected, actual)
|
||||
}
|
||||
|
||||
func TestNormalizeClasspathExceptionLicensesPreservesOtherLicenses(t *testing.T) {
|
||||
found := []pkg.License{
|
||||
{SPDXExpression: "EPL-2.0"},
|
||||
{SPDXExpression: "GPL-2.0-only"},
|
||||
{SPDXExpression: "MIT"},
|
||||
}
|
||||
|
||||
assert.Equal(t, found, normalizeClasspathExceptionLicenses(found, "## CLASSPATH EXCEPTION"))
|
||||
}
|
||||
|
||||
func TestParseJar(t *testing.T) {
|
||||
ctx := pkgtest.Context(t)
|
||||
tests := []struct {
|
||||
|
||||
@@ -261,13 +261,71 @@ func selectLicenses(manifest *pkg.JavaManifest) []string {
|
||||
|
||||
for _, fieldName := range fieldNames {
|
||||
if v := fieldValueFromManifest(*manifest, fieldName); v != "" {
|
||||
result = append(result, v)
|
||||
if fieldName != "Bundle-License" {
|
||||
result = append(result, v)
|
||||
continue
|
||||
}
|
||||
|
||||
clauses := splitUnquoted(v, ',')
|
||||
for i := 0; i < len(clauses); i++ {
|
||||
identifier := strings.TrimSpace(splitUnquoted(clauses[i], ';')[0])
|
||||
// Some bundles, including FreeMarker, leave this comma-containing name unquoted.
|
||||
if strings.EqualFold(strings.TrimSpace(clauses[i]), "Apache License") && i+1 < len(clauses) &&
|
||||
strings.EqualFold(strings.TrimSpace(splitUnquoted(clauses[i+1], ';')[0]), "Version 2.0") {
|
||||
identifier += ", Version 2.0"
|
||||
i++
|
||||
}
|
||||
if strings.EqualFold(strings.Trim(identifier, `"'`), "Apache License, Version 2.0") {
|
||||
identifier = "Apache-2.0"
|
||||
}
|
||||
if identifier != "" {
|
||||
result = append(result, identifier)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
func splitUnquoted(value string, delimiter rune) []string {
|
||||
var parts []string
|
||||
var current strings.Builder
|
||||
var quote rune
|
||||
escaped := false
|
||||
|
||||
for _, r := range value {
|
||||
if escaped {
|
||||
current.WriteRune(r)
|
||||
escaped = false
|
||||
continue
|
||||
}
|
||||
if quote != 0 && r == '\\' {
|
||||
current.WriteRune(r)
|
||||
escaped = true
|
||||
continue
|
||||
}
|
||||
if r == '\'' || r == '"' {
|
||||
switch quote {
|
||||
case 0:
|
||||
quote = r
|
||||
case r:
|
||||
quote = 0
|
||||
}
|
||||
current.WriteRune(r)
|
||||
continue
|
||||
}
|
||||
if quote == 0 && r == delimiter {
|
||||
parts = append(parts, current.String())
|
||||
current.Reset()
|
||||
continue
|
||||
}
|
||||
current.WriteRune(r)
|
||||
}
|
||||
|
||||
return append(parts, current.String())
|
||||
}
|
||||
|
||||
func fieldValueFromManifest(manifest pkg.JavaManifest, fieldName string) string {
|
||||
if value := manifest.Main.MustGet(fieldName); value != "" {
|
||||
return value
|
||||
|
||||
@@ -194,6 +194,95 @@ func TestParseJavaManifest(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestSelectLicensesSplitsBundleLicenseClauses(t *testing.T) {
|
||||
manifest := &pkg.JavaManifest{
|
||||
Main: pkg.KeyValues{
|
||||
{
|
||||
Key: "Bundle-License",
|
||||
Value: "https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt;description=\"EPL, version 2\", " +
|
||||
"https://www.gnu.org/software/classpath/license.html",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
assert.Equal(t, []string{
|
||||
"https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt",
|
||||
"https://www.gnu.org/software/classpath/license.html",
|
||||
}, selectLicenses(manifest))
|
||||
}
|
||||
|
||||
func TestSelectLicensesApacheName(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
value string
|
||||
expected []string
|
||||
}{
|
||||
{
|
||||
name: "freemarker unquoted name with see parameter",
|
||||
value: "Apache License, Version 2.0; see: http://www.apache.org/licenses/LICENSE-2.0.txt",
|
||||
expected: []string{"Apache-2.0"},
|
||||
},
|
||||
{
|
||||
name: "unquoted name",
|
||||
value: "Apache License, Version 2.0",
|
||||
expected: []string{"Apache-2.0"},
|
||||
},
|
||||
{
|
||||
name: "quoted name",
|
||||
value: `"Apache License, Version 2.0";description="Apache, version 2"`,
|
||||
expected: []string{"Apache-2.0"},
|
||||
},
|
||||
{
|
||||
name: "single quoted name",
|
||||
value: "'Apache License, Version 2.0'",
|
||||
expected: []string{"Apache-2.0"},
|
||||
},
|
||||
{
|
||||
name: "other licenses before and after",
|
||||
value: "MIT, Apache License, Version 2.0;description=Apache, BSD-3-Clause",
|
||||
expected: []string{"MIT", "Apache-2.0", "BSD-3-Clause"},
|
||||
},
|
||||
{
|
||||
name: "case and whitespace",
|
||||
value: " apache license , version 2.0 ;description=Apache ",
|
||||
expected: []string{"Apache-2.0"},
|
||||
},
|
||||
{
|
||||
name: "different version",
|
||||
value: "Apache License, Version 1.0",
|
||||
expected: []string{"Apache License", "Version 1.0"},
|
||||
},
|
||||
{
|
||||
name: "different license name",
|
||||
value: "Custom License, Version 2.0",
|
||||
expected: []string{"Custom License", "Version 2.0"},
|
||||
},
|
||||
{
|
||||
name: "comma in description",
|
||||
value: `MIT;description="Apache License, Version 2.0", BSD-3-Clause`,
|
||||
expected: []string{"MIT", "BSD-3-Clause"},
|
||||
},
|
||||
{
|
||||
name: "parameter separates the two clauses",
|
||||
value: "Apache License;description=custom, Version 2.0",
|
||||
expected: []string{"Apache License", "Version 2.0"},
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
manifest := &pkg.JavaManifest{Main: pkg.KeyValues{{Key: "Bundle-License", Value: test.value}}}
|
||||
actual := selectLicenses(manifest)
|
||||
assert.Equal(t, test.expected, actual)
|
||||
for _, license := range pkg.NewLicensesFromValuesWithContext(t.Context(), actual...) {
|
||||
if license.Value == "Apache-2.0" {
|
||||
assert.Equal(t, "Apache-2.0", license.SPDXExpression)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestSelectName(t *testing.T) {
|
||||
tests := []struct {
|
||||
desc string
|
||||
|
||||
@@ -301,6 +301,83 @@ func Test_InstalledPackageCataloger(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "detect license files under dist-info/licenses (PEP 639)",
|
||||
fixture: "testdata/site-packages/license-pep639",
|
||||
expectedPackages: []pkg.Package{
|
||||
{
|
||||
Name: "pep639-example",
|
||||
Version: "1.0.0",
|
||||
PURL: "pkg:pypi/pep639-example@1.0.0",
|
||||
Type: pkg.PythonPkg,
|
||||
Language: pkg.Python,
|
||||
Locations: file.NewLocationSet(
|
||||
file.NewLocation("pep639_example-1.0.0.dist-info/METADATA"),
|
||||
file.NewLocation("pep639_example-1.0.0.dist-info/RECORD"),
|
||||
),
|
||||
Licenses: pkg.NewLicenseSet(
|
||||
pkg.License{
|
||||
Value: "BSD-3-Clause",
|
||||
SPDXExpression: "BSD-3-Clause",
|
||||
Type: "concluded",
|
||||
Contents: mustContentsFromLocation(t, "testdata/site-packages/license-pep639/pep639_example-1.0.0.dist-info/licenses/LICENSE", 0, 1475),
|
||||
// no License-File is declared, so the license file is found through RECORD
|
||||
Locations: file.NewLocationSet(file.NewLocation("pep639_example-1.0.0.dist-info/licenses/LICENSE")),
|
||||
},
|
||||
),
|
||||
FoundBy: "python-installed-package-cataloger",
|
||||
Metadata: pkg.PythonPackage{
|
||||
Name: "pep639-example",
|
||||
Version: "1.0.0",
|
||||
SitePackagesRootPath: ".",
|
||||
Files: []pkg.PythonFileRecord{
|
||||
{Path: "pep639_example-1.0.0.dist-info/METADATA", Digest: &pkg.PythonFileDigest{Algorithm: "sha256", Value: "Z_-WBDzq246VHj56DO8yfBNNtlTqMj6q9xw_OGgeEMw"}, Size: "218"},
|
||||
{Path: "pep639_example-1.0.0.dist-info/licenses/LICENSE", Digest: &pkg.PythonFileDigest{Algorithm: "sha256", Value: "SJqOEQhQntmKN7uYPhHg9-HTHwvY-Zp5yESOf_N9B-o"}, Size: "1475"},
|
||||
{Path: "pep639_example-1.0.0.dist-info/RECORD"},
|
||||
},
|
||||
RequiresPython: ">=3.9",
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "pep639-declared",
|
||||
Version: "1.0.0",
|
||||
PURL: "pkg:pypi/pep639-declared@1.0.0",
|
||||
Type: pkg.PythonPkg,
|
||||
Language: pkg.Python,
|
||||
Locations: file.NewLocationSet(
|
||||
file.NewLocation("pep639_declared-1.0.0.dist-info/METADATA"),
|
||||
file.NewLocation("pep639_declared-1.0.0.dist-info/RECORD"),
|
||||
),
|
||||
// found only through License-File, since RECORD does not list them; AUTHORS.rst is not a license file
|
||||
Licenses: pkg.NewLicenseSet(
|
||||
pkg.License{
|
||||
Value: "BSD-3-Clause",
|
||||
SPDXExpression: "BSD-3-Clause",
|
||||
Type: "concluded",
|
||||
Contents: mustContentsFromLocation(t, "testdata/site-packages/license-pep639/pep639_declared-1.0.0.dist-info/licenses/LICENSE.BSD", 0, 1475),
|
||||
Locations: file.NewLocationSet(file.NewLocation("pep639_declared-1.0.0.dist-info/licenses/LICENSE.BSD")),
|
||||
},
|
||||
pkg.License{
|
||||
Value: "MIT",
|
||||
SPDXExpression: "MIT",
|
||||
Type: "concluded",
|
||||
Contents: mustContentsFromLocation(t, "testdata/site-packages/license-pep639/pep639_declared-1.0.0.dist-info/licenses/LICENSE.MIT", 13, 1072),
|
||||
Locations: file.NewLocationSet(file.NewLocation("pep639_declared-1.0.0.dist-info/licenses/LICENSE.MIT")),
|
||||
},
|
||||
),
|
||||
FoundBy: "python-installed-package-cataloger",
|
||||
Metadata: pkg.PythonPackage{
|
||||
Name: "pep639-declared",
|
||||
Version: "1.0.0",
|
||||
SitePackagesRootPath: ".",
|
||||
Files: []pkg.PythonFileRecord{
|
||||
{Path: "pep639_declared-1.0.0.dist-info/METADATA", Digest: &pkg.PythonFileDigest{Algorithm: "sha256", Value: "QM0YKaGTutHOanSl_CjBQDgF2cayCxbgyEPE0xhMGks"}, Size: "255"},
|
||||
{Path: "pep639_declared-1.0.0.dist-info/RECORD"},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "malformed-record",
|
||||
fixture: "testdata/site-packages/malformed-record",
|
||||
|
||||
@@ -26,7 +26,7 @@ const (
|
||||
// --hash=sha256:e9535b8c84dc9571a48999094fda7f33e63c3f1b74f3e5f3ac0105a58405bb65 # some comment
|
||||
|
||||
// namePattern matches: requests[security]
|
||||
namePattern = `(?P<name>\w[\w\[\],\s-_\.]+)`
|
||||
namePattern = `(?P<name>\w[\w\[\],\s-_\.]*)`
|
||||
|
||||
// versionConstraintPattern matches: == 2.8.*
|
||||
// the version token accepts every character PEP 440 versions can contain: digits and letters,
|
||||
|
||||
@@ -318,6 +318,21 @@ func Test_newRequirement(t *testing.T) {
|
||||
VersionConstraint: "==2.8",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "single character name",
|
||||
raw: "q==2.7",
|
||||
want: &unprocessedRequirement{
|
||||
Name: "q",
|
||||
VersionConstraint: "==2.7",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "single character name without version",
|
||||
raw: "q",
|
||||
want: &unprocessedRequirement{
|
||||
Name: "q",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "arbitrary equality",
|
||||
raw: "urllib3===1.26.20",
|
||||
|
||||
@@ -137,6 +137,9 @@ func extractUvExtras(p uvPackage) []pkg.PythonUvLockExtraEntry {
|
||||
Dependencies: extraDeps,
|
||||
})
|
||||
}
|
||||
sort.Slice(extras, func(i, j int) bool {
|
||||
return extras[i].Name < extras[j].Name
|
||||
})
|
||||
return extras
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,8 @@ import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/anchore/syft/syft/artifact"
|
||||
"github.com/anchore/syft/syft/file"
|
||||
"github.com/anchore/syft/syft/pkg"
|
||||
@@ -253,3 +255,23 @@ func TestParseUvLockWithLicenseEnrichment(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestExtractUvExtrasIsSortedByName(t *testing.T) {
|
||||
p := uvPackage{
|
||||
OptionalDependencies: map[string]uvDependencies{
|
||||
"socks": {{Name: "socksio"}},
|
||||
"brotli": {{Name: "brotli"}, {Name: "brotlicffi"}},
|
||||
"http2": {{Name: "h2"}},
|
||||
"cli": {{Name: "click"}, {Name: "rich"}},
|
||||
},
|
||||
}
|
||||
|
||||
// map iteration order is randomized, so check many runs rather than one
|
||||
for i := 0; i < 50; i++ {
|
||||
var names []string
|
||||
for _, e := range extractUvExtras(p) {
|
||||
names = append(names, e.Name)
|
||||
}
|
||||
assert.Equal(t, []string{"brotli", "cli", "http2", "socks"}, names)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -251,6 +251,15 @@ func findLicenses(ctx context.Context, resolver file.Resolver, m parsedData) pkg
|
||||
} else {
|
||||
licenseLocations.Add(locs...)
|
||||
}
|
||||
} else {
|
||||
metadataDir := path.Dir(m.DistInfoLocation.Path())
|
||||
for _, name := range m.LicenseFiles {
|
||||
// License-File may also list notices such as AUTHORS, which are not licenses
|
||||
if !licenses.IsLicenseFile(path.Base(name)) {
|
||||
continue
|
||||
}
|
||||
licenseLocations.Add(resolveDeclaredLicenseFile(resolver, metadataDir, name)...)
|
||||
}
|
||||
}
|
||||
|
||||
switch {
|
||||
@@ -264,7 +273,7 @@ func findLicenses(ctx context.Context, resolver file.Resolver, m parsedData) pkg
|
||||
parent := path.Base(path.Dir(m.DistInfoLocation.LocalPath()))
|
||||
candidatePaths := strset.New()
|
||||
for _, f := range m.Files {
|
||||
if !strings.HasPrefix(f.Path, parent) || strings.Count(f.Path, "/") > 1 {
|
||||
if !isDistInfoLicenseCandidate(parent, f.Path) {
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -277,3 +286,29 @@ func findLicenses(ctx context.Context, resolver file.Resolver, m parsedData) pkg
|
||||
}
|
||||
return pkg.NewLicenseSet(out...)
|
||||
}
|
||||
|
||||
// resolveDeclaredLicenseFile finds a License-File entry, which PEP 639 (Metadata-Version 2.4) makes relative to
|
||||
// .dist-info/licenses/ and older metadata makes relative to the metadata directory itself.
|
||||
func resolveDeclaredLicenseFile(resolver file.Resolver, metadataDir, name string) []file.Location {
|
||||
for _, p := range []string{path.Join(metadataDir, name), path.Join(metadataDir, "licenses", name)} {
|
||||
locs, err := resolver.FilesByPath(p)
|
||||
if err != nil {
|
||||
log.WithFields("error", err, "path", p).Trace("unable to resolve python license file")
|
||||
continue
|
||||
}
|
||||
if len(locs) > 0 {
|
||||
return locs
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// isDistInfoLicenseCandidate reports whether a RECORD path sits directly in the .dist-info directory,
|
||||
// or anywhere under its licenses/ subdirectory, where PEP 639 places license files.
|
||||
func isDistInfoLicenseCandidate(distInfoDir, recordPath string) bool {
|
||||
rel, found := strings.CutPrefix(recordPath, distInfoDir+"/")
|
||||
if !found {
|
||||
return false
|
||||
}
|
||||
return !strings.Contains(rel, "/") || strings.HasPrefix(rel, "licenses/")
|
||||
}
|
||||
|
||||
@@ -23,13 +23,14 @@ type parsedData struct {
|
||||
|
||||
// license info
|
||||
|
||||
Licenses string `mapstructure:"License"`
|
||||
LicenseFile string `mapstructure:"LicenseFile"`
|
||||
LicenseExpression string `mapstructure:"LicenseExpression"`
|
||||
Licenses string `mapstructure:"License"`
|
||||
LicenseFiles []string `mapstructure:"LicenseFile"`
|
||||
LicenseExpression string `mapstructure:"LicenseExpression"`
|
||||
LicenseFilePath string
|
||||
}
|
||||
|
||||
var pluralFields = map[string]bool{
|
||||
"LicenseFile": true,
|
||||
"ProvidesExtra": true,
|
||||
"RequiresDist": true,
|
||||
}
|
||||
@@ -53,8 +54,6 @@ func parseWheelOrEggMetadata(locationReader file.LocationReadCloser) (parsedData
|
||||
pd.SitePackagesRootPath = determineSitePackagesRootPath(metadataPath)
|
||||
if pd.Licenses != "" || pd.LicenseExpression != "" {
|
||||
pd.LicenseFilePath = metadataPath
|
||||
} else if pd.LicenseFile != "" {
|
||||
pd.LicenseFilePath = path.Join(path.Dir(metadataPath), pd.LicenseFile)
|
||||
}
|
||||
|
||||
pd.DistInfoLocation = locationReader.Location
|
||||
|
||||
@@ -26,7 +26,6 @@ func TestParseWheelEggMetadata(t *testing.T) {
|
||||
ExpectedMetadata: parsedData{
|
||||
DistInfoLocation: file.NewLocation("testdata/site-packages/nested/egg-name/egg-info/PKG-INFO"),
|
||||
Licenses: "Apache 2.0",
|
||||
LicenseFile: "",
|
||||
LicenseExpression: "",
|
||||
LicenseFilePath: "testdata/site-packages/nested/egg-name/egg-info/PKG-INFO",
|
||||
PythonPackage: pkg.PythonPackage{
|
||||
@@ -46,7 +45,6 @@ func TestParseWheelEggMetadata(t *testing.T) {
|
||||
ExpectedMetadata: parsedData{
|
||||
DistInfoLocation: file.NewLocation("testdata/site-packages/nested/dist-name/dist-info/METADATA"),
|
||||
Licenses: "BSD License",
|
||||
LicenseFile: "",
|
||||
LicenseExpression: "",
|
||||
LicenseFilePath: "testdata/site-packages/nested/dist-name/dist-info/METADATA",
|
||||
PythonPackage: pkg.PythonPackage{
|
||||
@@ -156,7 +154,6 @@ func TestParseWheelEggMetadataInvalid(t *testing.T) {
|
||||
DistInfoLocation: file.NewLocation("testdata/site-packages/nested/egg-name/egg-info/PKG-INFO-INVALID"),
|
||||
Licenses: "",
|
||||
LicenseExpression: "",
|
||||
LicenseFile: "",
|
||||
LicenseFilePath: "",
|
||||
PythonPackage: pkg.PythonPackage{
|
||||
Name: "mxnet",
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
package python
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func Test_isDistInfoLicenseCandidate(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
recordPath string
|
||||
want bool
|
||||
}{
|
||||
{name: "directly in dist-info", recordPath: "x.dist-info/LICENSE", want: true},
|
||||
{name: "under licenses", recordPath: "x.dist-info/licenses/LICENSE", want: true},
|
||||
{name: "nested under licenses", recordPath: "x.dist-info/licenses/vendor/LICENSE", want: true},
|
||||
{name: "other subdirectory of dist-info", recordPath: "x.dist-info/sub/LICENSE", want: false},
|
||||
{name: "sibling directory sharing the prefix", recordPath: "x.dist-info2/LICENSE", want: false},
|
||||
{name: "outside dist-info", recordPath: "x/LICENSE", want: false},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
assert.Equal(t, tt.want, isDistInfoLicenseCandidate("x.dist-info", tt.recordPath))
|
||||
})
|
||||
}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
Metadata-Version: 2.4
|
||||
Name: pep639-declared
|
||||
Version: 1.0.0
|
||||
Summary: A package that declares two license files under .dist-info/licenses/ (PEP 639), which RECORD does not list.
|
||||
License-File: LICENSE.BSD
|
||||
License-File: LICENSE.MIT
|
||||
License-File: AUTHORS.rst
|
||||
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
pep639_declared-1.0.0.dist-info/METADATA,sha256=QM0YKaGTutHOanSl_CjBQDgF2cayCxbgyEPE0xhMGks,255
|
||||
pep639_declared-1.0.0.dist-info/RECORD,,
|
||||
+1
@@ -0,0 +1 @@
|
||||
Example Authors <authors@example.com>
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
Copyright 2010 Pallets
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
||||
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2026 Example Authors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
Metadata-Version: 2.4
|
||||
Name: pep639-example
|
||||
Version: 1.0.0
|
||||
Summary: A package that ships its license only under .dist-info/licenses/ (PEP 639).
|
||||
Classifier: License :: OSI Approved :: BSD License
|
||||
Requires-Python: >=3.9
|
||||
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
pep639_example-1.0.0.dist-info/METADATA,sha256=Z_-WBDzq246VHj56DO8yfBNNtlTqMj6q9xw_OGgeEMw,218
|
||||
pep639_example-1.0.0.dist-info/licenses/LICENSE,sha256=SJqOEQhQntmKN7uYPhHg9-HTHwvY-Zp5yESOf_N9B-o,1475
|
||||
pep639_example-1.0.0.dist-info/RECORD,,
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
Copyright 2010 Pallets
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
||||
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
@@ -143,7 +143,7 @@ func (s fileSource) Describe() source.Description {
|
||||
}
|
||||
}
|
||||
|
||||
func (s fileSource) FileResolver(_ source.Scope) (file.Resolver, error) {
|
||||
func (s *fileSource) FileResolver(_ source.Scope) (file.Resolver, error) {
|
||||
s.mutex.Lock()
|
||||
defer s.mutex.Unlock()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user