mirror of
https://github.com/anchore/syft.git
synced 2026-10-31 06:26:30 +01:00
fix: keep the access path of archives discovered through a link
`discoverArchives` collects MIME hits first, and those are bare real paths. When the glob pass then found the same file through a symlink, it was dropped as a duplicate along with its access path. Java decides whether to describe an archive by its name, so a content-addressed jar (`store/3f9a1c`, linked from `lib/json-simple-1.1.1.jar`) was extracted but produced no package. This is the pnpm / nix / bazel layout. When deduping, the candidate now takes the first location that carries an access path. Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
This commit is contained in:
@@ -330,6 +330,31 @@ func TestArchiveCataloger_featureOff(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestArchiveCataloger_jarReachedThroughALinkIsIdentified(t *testing.T) {
|
||||
// a content-addressed layout (pnpm, nix, bazel): the jar is stored under a hash and only the link
|
||||
// to it is named like a jar
|
||||
var buf bytes.Buffer
|
||||
gw := gzip.NewWriter(&buf)
|
||||
tw := tar.NewWriter(gw)
|
||||
jar := jarBytes(t, "json-simple", "1.1.1")
|
||||
require.NoError(t, tw.WriteHeader(&tar.Header{Name: "store/3f9a1c", Mode: 0o644, Size: int64(len(jar))}))
|
||||
_, err := tw.Write(jar)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, tw.WriteHeader(&tar.Header{Name: "app/lib/json-simple-1.1.1.jar", Typeflag: tar.TypeSymlink, Linkname: "../../store/3f9a1c"}))
|
||||
require.NoError(t, tw.Close())
|
||||
require.NoError(t, gw.Close())
|
||||
|
||||
dir := t.TempDir()
|
||||
require.NoError(t, os.WriteFile(filepath.Join(dir, "bundle.tar.gz"), buf.Bytes(), 0o644))
|
||||
|
||||
cfg := DefaultCreateSBOMConfig().
|
||||
WithCatalogerSelection(cataloging.NewSelectionRequest().WithDefaults("java")).
|
||||
WithArchiveConfig(cataloging.DefaultArchiveSearchConfig().WithMaxDepth(2))
|
||||
s := scanDirWithExclusions(t, dir, cfg)
|
||||
|
||||
assert.Equal(t, []string{"bundle.tar.gz|store/3f9a1c"}, packageLocations(s, "json-simple"))
|
||||
}
|
||||
|
||||
func TestArchiveCataloger_descriptorRecordsArchiveConfig(t *testing.T) {
|
||||
// a consumer must be able to tell from the SBOM alone how deep archive contents were searched
|
||||
cfg := DefaultCreateSBOMConfig().
|
||||
|
||||
Reference in New Issue
Block a user