From 39bd8c6cf58fec051f53a498d865cdae4a5d9f92 Mon Sep 17 00:00:00 2001 From: Yan Song Date: Fri, 24 Feb 2023 11:14:44 +0000 Subject: [PATCH] fix a possible panic on cache ``` newDesc.Annotations = nil for _, k := range addAnnotations { newDesc.Annotations[k] = desc.Annotations[k] } ``` The codes may cause buildkitd panic: assignment to entry in nil map Signed-off-by: Yan Song --- cache/remote.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cache/remote.go b/cache/remote.go index 843ad2497..b80bd79cf 100644 --- a/cache/remote.go +++ b/cache/remote.go @@ -228,13 +228,13 @@ func (sr *immutableRef) getRemote(ctx context.Context, createIfNeeded bool, refC newDesc.Size = blobDesc.Size newDesc.URLs = blobDesc.URLs newDesc.Annotations = nil + if len(addAnnotations) > 0 || len(blobDesc.Annotations) > 0 { + newDesc.Annotations = make(map[string]string) + } for _, k := range addAnnotations { newDesc.Annotations[k] = desc.Annotations[k] } for k, v := range blobDesc.Annotations { - if newDesc.Annotations == nil { - newDesc.Annotations = make(map[string]string) - } newDesc.Annotations[k] = v } desc = newDesc