From ef2b4436cb5500846ed0772da9a624abf4565ca5 Mon Sep 17 00:00:00 2001 From: Tonis Tiigi Date: Thu, 2 Oct 2025 10:36:48 -0700 Subject: [PATCH] imagetools: fix possible broken chain copy on create When creating index from singe-arch manifests it was possible for some of the internal manifests to not be copies and cause error on pushing the index. Signed-off-by: Tonis Tiigi --- commands/imagetools/create.go | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/commands/imagetools/create.go b/commands/imagetools/create.go index c23935b29..5e2c23174 100644 --- a/commands/imagetools/create.go +++ b/commands/imagetools/create.go @@ -240,13 +240,12 @@ type descWithSource struct { } func filterPlatforms(dt []byte, desc ocispecs.Descriptor, srcMap map[digest.Digest]*imagetools.Source, plats []ocispecs.Platform) ([]byte, ocispecs.Descriptor, []descWithSource, error) { - if len(plats) == 0 { - return dt, desc, nil, nil - } - matcher := platforms.Any(plats...) if !images.IsIndexType(desc.MediaType) { + if len(plats) == 0 { + return dt, desc, nil, nil + } var mfst ocispecs.Manifest if err := json.Unmarshal(dt, &mfst); err != nil { return nil, ocispecs.Descriptor{}, nil, errors.Wrapf(err, "failed to parse manifest") @@ -264,6 +263,24 @@ func filterPlatforms(dt []byte, desc ocispecs.Descriptor, srcMap map[digest.Dige if err := json.Unmarshal(dt, &idx); err != nil { return nil, ocispecs.Descriptor{}, nil, errors.Wrapf(err, "failed to parse index") } + if len(plats) == 0 { + mfsts := make([]descWithSource, len(idx.Manifests)) + for i, m := range idx.Manifests { + src, ok := srcMap[m.Digest] + if !ok { + defaultSource, ok := srcMap[desc.Digest] + if !ok { + return nil, ocispecs.Descriptor{}, nil, errors.Errorf("internal error: no source found for %s", m.Digest) + } + src = defaultSource + } + mfsts[i] = descWithSource{ + Descriptor: m, + Source: src, + } + } + return dt, desc, mfsts, nil + } manifestMap := map[digest.Digest]ocispecs.Descriptor{} for _, m := range idx.Manifests {