From 95bdecc145b272e09c3fa9d12a097b6f055b38a5 Mon Sep 17 00:00:00 2001 From: Justin Chadwell Date: Wed, 31 Jan 2024 14:44:10 +0000 Subject: [PATCH] fix: avoid modifying source during resolver.Copy Signed-off-by: Justin Chadwell --- util/imagetools/create.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/util/imagetools/create.go b/util/imagetools/create.go index 1b55f083357..d1e8dfaadc8 100644 --- a/util/imagetools/create.go +++ b/util/imagetools/create.go @@ -4,6 +4,7 @@ import ( "bytes" "context" "encoding/json" + "maps" "net/url" "strings" @@ -230,13 +231,17 @@ func (r *Resolver) Copy(ctx context.Context, src *Source, dest reference.Named) if err != nil { return err } - source, repo := u.Hostname(), strings.TrimPrefix(u.Path, "/") - if src.Desc.Annotations == nil { - src.Desc.Annotations = make(map[string]string) + + desc := src.Desc + desc.Annotations = maps.Clone(desc.Annotations) + if desc.Annotations == nil { + desc.Annotations = make(map[string]string) } - src.Desc.Annotations["containerd.io/distribution.source."+source] = repo - err = contentutil.CopyChain(ctx, contentutil.FromPusher(p), contentutil.FromFetcher(f), src.Desc) + source, repo := u.Hostname(), strings.TrimPrefix(u.Path, "/") + desc.Annotations["containerd.io/distribution.source."+source] = repo + + err = contentutil.CopyChain(ctx, contentutil.FromPusher(p), contentutil.FromFetcher(f), desc) if err != nil { return err }