diff --git a/cmd/syft/internal/test/integration/dpkg_status_dir_test.go b/cmd/syft/internal/test/integration/dpkg_status_dir_test.go new file mode 100644 index 000000000..0c240bf95 --- /dev/null +++ b/cmd/syft/internal/test/integration/dpkg_status_dir_test.go @@ -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 +} diff --git a/cmd/syft/internal/test/integration/testdata/image-dpkg-status-and-status-d/Dockerfile b/cmd/syft/internal/test/integration/testdata/image-dpkg-status-and-status-d/Dockerfile new file mode 100644 index 000000000..71744eb6b --- /dev/null +++ b/cmd/syft/internal/test/integration/testdata/image-dpkg-status-and-status-d/Dockerfile @@ -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/ 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/ / diff --git a/cmd/syft/internal/test/integration/testdata/image-dpkg-status-and-status-d/packages/var/lib/dpkg/status.d/bzip2 b/cmd/syft/internal/test/integration/testdata/image-dpkg-status-and-status-d/packages/var/lib/dpkg/status.d/bzip2 new file mode 100644 index 000000000..438ebf96c --- /dev/null +++ b/cmd/syft/internal/test/integration/testdata/image-dpkg-status-and-status-d/packages/var/lib/dpkg/status.d/bzip2 @@ -0,0 +1,23 @@ +Package: bzip2 +Version: 1.0.8-6+dhi2 +Architecture: arm64 +Maintainer: Docker Hardened Images +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). diff --git a/cmd/syft/internal/test/integration/testdata/image-dpkg-status-and-status-d/packages/var/lib/dpkg/status.d/gzip b/cmd/syft/internal/test/integration/testdata/image-dpkg-status-and-status-d/packages/var/lib/dpkg/status.d/gzip new file mode 100644 index 000000000..359ea66d8 --- /dev/null +++ b/cmd/syft/internal/test/integration/testdata/image-dpkg-status-and-status-d/packages/var/lib/dpkg/status.d/gzip @@ -0,0 +1,17 @@ +Package: gzip +Version: 1.13-1+dhi1 +Architecture: arm64 +Essential: yes +Maintainer: Docker Hardened Images +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'. diff --git a/cmd/syft/internal/test/integration/testdata/image-dpkg-status-and-status-d/status-base/var/lib/dpkg/status b/cmd/syft/internal/test/integration/testdata/image-dpkg-status-and-status-d/status-base/var/lib/dpkg/status new file mode 100644 index 000000000..4f43b9f16 --- /dev/null +++ b/cmd/syft/internal/test/integration/testdata/image-dpkg-status-and-status-d/status-base/var/lib/dpkg/status @@ -0,0 +1,19 @@ +Package: gzip +Status: install ok installed +Version: 1.13-1+dhi1 +Architecture: arm64 +Essential: yes +Maintainer: Docker Hardened Images +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'. + diff --git a/cmd/syft/internal/test/integration/testdata/image-dpkg-status-and-status-d/status-updated/var/lib/dpkg/status b/cmd/syft/internal/test/integration/testdata/image-dpkg-status-and-status-d/status-updated/var/lib/dpkg/status new file mode 100644 index 000000000..4685a93b4 --- /dev/null +++ b/cmd/syft/internal/test/integration/testdata/image-dpkg-status-and-status-d/status-updated/var/lib/dpkg/status @@ -0,0 +1,39 @@ +Package: gzip +Status: install ok installed +Version: 1.13-1+dhi1 +Architecture: arm64 +Essential: yes +Maintainer: Docker Hardened Images +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 +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. + diff --git a/syft/pkg/cataloger/debian/cataloger.go b/syft/pkg/cataloger/debian/cataloger.go index 0bdd6d066..d4561a456 100644 --- a/syft/pkg/cataloger/debian/cataloger.go +++ b/syft/pkg/cataloger/debian/cataloger.go @@ -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 diff --git a/syft/pkg/cataloger/debian/package.go b/syft/pkg/cataloger/debian/package.go index 28b09256d..afed26cbd 100644 --- a/syft/pkg/cataloger/debian/package.go +++ b/syft/pkg/cataloger/debian/package.go @@ -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") } diff --git a/syft/pkg/cataloger/debian/parse_dpkg_db.go b/syft/pkg/cataloger/debian/parse_dpkg_db.go index 8ab89c5ca..72f58b780 100644 --- a/syft/pkg/cataloger/debian/parse_dpkg_db.go +++ b/syft/pkg/cataloger/debian/parse_dpkg_db.go @@ -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") } diff --git a/syft/pkg/cataloger/debian/status_dir_processor.go b/syft/pkg/cataloger/debian/status_dir_processor.go new file mode 100644 index 000000000..1b4de83bf --- /dev/null +++ b/syft/pkg/cataloger/debian/status_dir_processor.go @@ -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/ 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 +} diff --git a/syft/pkg/cataloger/debian/status_dir_processor_test.go b/syft/pkg/cataloger/debian/status_dir_processor_test.go new file mode 100644 index 000000000..08ff6f030 --- /dev/null +++ b/syft/pkg/cataloger/debian/status_dir_processor_test.go @@ -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/.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/. 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()) + } +} diff --git a/syft/pkg/cataloger/debian/testdata/status-and-status-d/var/lib/dpkg/info/gzip.md5sums b/syft/pkg/cataloger/debian/testdata/status-and-status-d/var/lib/dpkg/info/gzip.md5sums new file mode 100644 index 000000000..03f05032b --- /dev/null +++ b/syft/pkg/cataloger/debian/testdata/status-and-status-d/var/lib/dpkg/info/gzip.md5sums @@ -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 diff --git a/syft/pkg/cataloger/debian/testdata/status-and-status-d/var/lib/dpkg/status b/syft/pkg/cataloger/debian/testdata/status-and-status-d/var/lib/dpkg/status new file mode 100644 index 000000000..4685a93b4 --- /dev/null +++ b/syft/pkg/cataloger/debian/testdata/status-and-status-d/var/lib/dpkg/status @@ -0,0 +1,39 @@ +Package: gzip +Status: install ok installed +Version: 1.13-1+dhi1 +Architecture: arm64 +Essential: yes +Maintainer: Docker Hardened Images +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 +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. + diff --git a/syft/pkg/cataloger/debian/testdata/status-and-status-d/var/lib/dpkg/status.d/bzip2 b/syft/pkg/cataloger/debian/testdata/status-and-status-d/var/lib/dpkg/status.d/bzip2 new file mode 100644 index 000000000..438ebf96c --- /dev/null +++ b/syft/pkg/cataloger/debian/testdata/status-and-status-d/var/lib/dpkg/status.d/bzip2 @@ -0,0 +1,23 @@ +Package: bzip2 +Version: 1.0.8-6+dhi2 +Architecture: arm64 +Maintainer: Docker Hardened Images +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). diff --git a/syft/pkg/cataloger/debian/testdata/status-and-status-d/var/lib/dpkg/status.d/gzip b/syft/pkg/cataloger/debian/testdata/status-and-status-d/var/lib/dpkg/status.d/gzip new file mode 100644 index 000000000..359ea66d8 --- /dev/null +++ b/syft/pkg/cataloger/debian/testdata/status-and-status-d/var/lib/dpkg/status.d/gzip @@ -0,0 +1,17 @@ +Package: gzip +Version: 1.13-1+dhi1 +Architecture: arm64 +Essential: yes +Maintainer: Docker Hardened Images +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'.