From d8d3b018247be19cb4df90230327b0c4bb235c96 Mon Sep 17 00:00:00 2001 From: Cheng Fang Date: Tue, 2 Jul 2024 09:01:53 -0400 Subject: [PATCH] fix: add check for the optional ref.Platform field to avoid nil pointer in TagInfoFromReferences (#759) Signed-off-by: Cheng Fang --- pkg/registry/client.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/pkg/registry/client.go b/pkg/registry/client.go index b92b2910..2c2ddde2 100644 --- a/pkg/registry/client.go +++ b/pkg/registry/client.go @@ -361,12 +361,18 @@ func TagInfoFromReferences(client *registryClient, opts *options.ManifestOptions platforms := []string{} for _, ref := range references { - platforms = append(platforms, ref.Platform.OS+"/"+ref.Platform.Architecture) - logCtx.Tracef("Found %s", options.PlatformKey(ref.Platform.OS, ref.Platform.Architecture, ref.Platform.Variant)) - if !opts.WantsPlatform(ref.Platform.OS, ref.Platform.Architecture, ref.Platform.Variant) { + var refOS, refArch, refVariant string + if ref.Platform != nil { + refOS = ref.Platform.OS + refArch = ref.Platform.Architecture + refVariant = ref.Platform.Variant + } + platforms = append(platforms, refOS+"/"+refArch) + logCtx.Tracef("Found %s", options.PlatformKey(refOS, refArch, refVariant)) + if !opts.WantsPlatform(refOS, refArch, refVariant) { logCtx.Tracef("Ignoring referenced manifest %v because platform %s does not match any of: %s", ref.Digest, - options.PlatformKey(ref.Platform.OS, ref.Platform.Architecture, ref.Platform.Variant), + options.PlatformKey(refOS, refArch, refVariant), strings.Join(opts.Platforms(), ",")) continue }