Skip to content

Commit 39bd8c6

Browse files
committed
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 <[email protected]>
1 parent 9cdc70a commit 39bd8c6

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

cache/remote.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,13 +228,13 @@ func (sr *immutableRef) getRemote(ctx context.Context, createIfNeeded bool, refC
228228
newDesc.Size = blobDesc.Size
229229
newDesc.URLs = blobDesc.URLs
230230
newDesc.Annotations = nil
231+
if len(addAnnotations) > 0 || len(blobDesc.Annotations) > 0 {
232+
newDesc.Annotations = make(map[string]string)
233+
}
231234
for _, k := range addAnnotations {
232235
newDesc.Annotations[k] = desc.Annotations[k]
233236
}
234237
for k, v := range blobDesc.Annotations {
235-
if newDesc.Annotations == nil {
236-
newDesc.Annotations = make(map[string]string)
237-
}
238238
newDesc.Annotations[k] = v
239239
}
240240
desc = newDesc

0 commit comments

Comments
 (0)