Skip to content

Commit 6770304

Browse files
authored
Update descriptor "data" field (when valid) during "crane edit config" (#1584)
Signed-off-by: Tianon Gravi <admwiggin@gmail.com>
1 parent 1b8dc2b commit 6770304

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

internal/cmd/edit.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"strings"
2727

2828
"github.com/google/go-containerregistry/internal/editor"
29+
"github.com/google/go-containerregistry/internal/verify"
2930
"github.com/google/go-containerregistry/pkg/crane"
3031
"github.com/google/go-containerregistry/pkg/name"
3132
v1 "github.com/google/go-containerregistry/pkg/v1"
@@ -188,6 +189,13 @@ func editConfig(in io.Reader, out io.Writer, src, dst string, options ...crane.O
188189
edited = b
189190
}
190191

192+
// this has to happen before we modify the descriptor (so we can use verify.Descriptor to validate whether m.Config.Data matches m.Config.Digest/Size)
193+
if m.Config.Data != nil && verify.Descriptor(m.Config) == nil {
194+
// https://github.com/google/go-containerregistry/issues/1552#issuecomment-1452653875
195+
// "if data is non-empty and correct, we should update it"
196+
m.Config.Data = edited
197+
}
198+
191199
l := static.NewLayer(edited, m.Config.MediaType)
192200
layerDigest, err := l.Digest()
193201
if err != nil {

0 commit comments

Comments
 (0)