Skip to content

Commit

Permalink
mutate: Create a defensive annotations copy (#2030)
Browse files Browse the repository at this point in the history
Since this is computed lazily, the caller can modify the map, which
would break the ~immutable nature of this API, so we create a defensive
copy.

Signed-off-by: Jon Johnson <[email protected]>
  • Loading branch information
jonjohnsonjr authored Oct 30, 2024
1 parent a9a53a8 commit 06dcd85
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions pkg/v1/mutate/mutate.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"errors"
"fmt"
"io"
"maps"
"path/filepath"
"strings"
"time"
Expand Down Expand Up @@ -165,16 +166,16 @@ func Annotations(f partial.WithRawManifest, anns map[string]string) partial.With
if img, ok := f.(v1.Image); ok {
return &image{
base: img,
annotations: anns,
annotations: maps.Clone(anns),
}
}
if idx, ok := f.(v1.ImageIndex); ok {
return &index{
base: idx,
annotations: anns,
annotations: maps.Clone(anns),
}
}
return arbitraryRawManifest{a: f, anns: anns}
return arbitraryRawManifest{a: f, anns: maps.Clone(anns)}
}

type arbitraryRawManifest struct {
Expand Down

0 comments on commit 06dcd85

Please sign in to comment.