diff --git a/pkg/v1/mutate/image.go b/pkg/v1/mutate/image.go index 727abe29c..3ea27fe47 100644 --- a/pkg/v1/mutate/image.go +++ b/pkg/v1/mutate/image.go @@ -18,6 +18,7 @@ import ( "bytes" "encoding/json" "errors" + "sync" v1 "github.com/google/go-containerregistry/pkg/v1" "github.com/google/go-containerregistry/pkg/v1/partial" @@ -38,6 +39,8 @@ type image struct { diffIDMap map[v1.Hash]v1.Layer digestMap map[v1.Hash]v1.Layer subject *v1.Descriptor + + sync.Mutex } var _ v1.Image = (*image)(nil) @@ -50,6 +53,9 @@ func (i *image) MediaType() (types.MediaType, error) { } func (i *image) compute() error { + i.Lock() + defer i.Unlock() + // Don't re-compute if already computed. if i.computed { return nil diff --git a/pkg/v1/mutate/index.go b/pkg/v1/mutate/index.go index ba062f9f1..593cf4654 100644 --- a/pkg/v1/mutate/index.go +++ b/pkg/v1/mutate/index.go @@ -17,6 +17,7 @@ package mutate import ( "encoding/json" "fmt" + "sync" "github.com/google/go-containerregistry/pkg/logs" v1 "github.com/google/go-containerregistry/pkg/v1" @@ -71,6 +72,8 @@ type index struct { indexMap map[v1.Hash]v1.ImageIndex layerMap map[v1.Hash]v1.Layer subject *v1.Descriptor + + sync.Mutex } var _ v1.ImageIndex = (*index)(nil) @@ -85,6 +88,9 @@ func (i *index) MediaType() (types.MediaType, error) { func (i *index) Size() (int64, error) { return partial.Size(i) } func (i *index) compute() error { + i.Lock() + defer i.Unlock() + // Don't re-compute if already computed. if i.computed { return nil