Skip to content

Commit e398498

Browse files
committed
provenance: fix possible empty digest access
If the digest for an ImageSource is the empty string, then calling `Digest.Algorithm` will panic at runtime. This scenario *can* happen if `ResolveImageConfig` returns an empty digest, but correctly returns a config object. This doesn't occur in buildkit directly, however, buildkit-in-moby implements a custom worker which also performs image lookups on local images, in which case the digest for the index may not be available (though this may be possible with the containerd image store?). Therefore, we shouldn't assume that the digest is always available in buildkit, and should instead check that is valid before inserting it into the digest set (which is already an optional map). Signed-off-by: Justin Chadwell <[email protected]>
1 parent bbeeef7 commit e398498

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

solver/llbsolver/provenance/predicate.go

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,15 @@ func slsaMaterials(srcs Sources) ([]slsa.ProvenanceMaterial, error) {
6464
if err != nil {
6565
return nil, err
6666
}
67-
out = append(out, slsa.ProvenanceMaterial{
67+
material := slsa.ProvenanceMaterial{
6868
URI: uri,
69-
Digest: slsa.DigestSet{
69+
}
70+
if s.Digest != "" {
71+
material.Digest = slsa.DigestSet{
7072
s.Digest.Algorithm().String(): s.Digest.Hex(),
71-
},
72-
})
73+
}
74+
}
75+
out = append(out, material)
7376
}
7477

7578
for _, s := range srcs.Git {
@@ -99,12 +102,16 @@ func slsaMaterials(srcs Sources) ([]slsa.ProvenanceMaterial, error) {
99102
})
100103
}
101104
packageurl.NewPackageURL(packageurl.TypeOCI, "", s.Ref, "", q, "")
102-
out = append(out, slsa.ProvenanceMaterial{
105+
106+
material := slsa.ProvenanceMaterial{
103107
URI: s.Ref,
104-
Digest: slsa.DigestSet{
108+
}
109+
if s.Digest != "" {
110+
material.Digest = slsa.DigestSet{
105111
s.Digest.Algorithm().String(): s.Digest.Hex(),
106-
},
107-
})
112+
}
113+
}
114+
out = append(out, material)
108115
}
109116
return out, nil
110117
}

0 commit comments

Comments
 (0)