mirror of
https://github.com/moby/buildkit.git
synced 2026-06-30 19:57:39 +00:00
remotecache: fix possible panic when merging loop candidates
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
This commit is contained in:
10
cache/remotecache/v1/chains.go
vendored
10
cache/remotecache/v1/chains.go
vendored
@@ -116,6 +116,12 @@ func (c *CacheChains) Add(dgst digest.Digest, deps [][]solver.CacheLink, results
|
||||
continue
|
||||
}
|
||||
for l, m := range it.children {
|
||||
if main.children == nil {
|
||||
main.children = map[unique.Handle[linkv2]]map[*item]struct{}{}
|
||||
}
|
||||
if _, ok := main.children[l]; !ok {
|
||||
main.children[l] = map[*item]struct{}{}
|
||||
}
|
||||
for ch := range m {
|
||||
main.children[l][ch] = struct{}{}
|
||||
for i, links := range ch.parents {
|
||||
@@ -126,7 +132,7 @@ func (c *CacheChains) Add(dgst digest.Digest, deps [][]solver.CacheLink, results
|
||||
}
|
||||
newlinks[l] = struct{}{}
|
||||
}
|
||||
main.parents[i] = newlinks
|
||||
ch.parents[i] = newlinks
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -143,7 +149,7 @@ func (c *CacheChains) Add(dgst digest.Digest, deps [][]solver.CacheLink, results
|
||||
r.addResult(rr)
|
||||
}
|
||||
|
||||
// make sure that none of the deps are childeren of r
|
||||
// make sure that none of the deps are children of r
|
||||
allChildren := map[*item]struct{}{}
|
||||
if err := r.walkChildren(func(i *item) error {
|
||||
allChildren[i] = struct{}{}
|
||||
|
||||
4
cache/remotecache/v1/utils.go
vendored
4
cache/remotecache/v1/utils.go
vendored
@@ -179,6 +179,7 @@ func marshalItem(ctx context.Context, it *item, state *marshalState) error {
|
||||
if _, ok := state.recordsByItem[it]; ok {
|
||||
return nil
|
||||
}
|
||||
state.recordsByItem[it] = -1
|
||||
|
||||
rec := CacheRecord{
|
||||
Digest: it.dgst,
|
||||
@@ -194,6 +195,9 @@ func marshalItem(ctx context.Context, it *item, state *marshalState) error {
|
||||
if !ok {
|
||||
return errors.Errorf("invalid source record: %v", l.src)
|
||||
}
|
||||
if idx == -1 {
|
||||
continue
|
||||
}
|
||||
rec.Inputs[i] = append(rec.Inputs[i], CacheInput{
|
||||
Selector: l.selector,
|
||||
LinkIndex: idx,
|
||||
|
||||
Reference in New Issue
Block a user