If I baked an index containing a manifest without platform information and tried to use oras manifest fetch --platform, then the execution will painc.
> oras manifest fetch --descriptor localhost:7000/command/images:multi1 --platform test/platform
Error: failed to find "localhost:7000/command/images:multi1": sha256:a75baa86dca530232c82eb68a5e97506aa85356e0ee5f1df852a01a9916fdca8: not found: no matching manifest was found in the manifest list
> cat test.platform.json
{"mediaType":"application/vnd.oci.image.index.v1+json","schemaVersion":2,"manifests":[{"mediaType":"application/vnd.oci.image.manifest.v1+json","digest":"sha256:9d84a5716c66a1d1b9c13f8ed157ba7d1edfe7f9b8766728b8a1f25c0d9c14c1","size":458},{"mediaType":"application/vnd.oci.image.manifest.v1+json","digest":"sha256:4f93460061882467e6fb3b772dc6ab72130d9ac1906aed2fc7589a5cd145433c","size":458,"platform":{"architecture":"arm64","os":"linux"}},{"mediaType":"application/vnd.oci.image.manifest.v1+json","digest":"sha256:58efe73e78fe043ca31b89007a025c594ce12aa7e6da27d21c7b14b50112e255","size":458,"platform":{"architecture":"arm","os":"linux","variant":"v7"}}]}
> oras manifest push localhost:7000/command/images:multi1 test.platform.json
Pushed [registry] localhost:7000/command/images:multi1
Digest: sha256:a75baa86dca530232c82eb68a5e97506aa85356e0ee5f1df852a01a9916fdca8
> oras manifest fetch --descriptor localhost:7000/command/images:multi1 --platform test/platform
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0x5e308d]
goroutine 1 [running]:
oras.land/oras-go/v2/internal/platform.Match(0x0, 0xc00009c900)
/home/runner/go/pkg/mod/oras.land/oras-go/v2@v2.3.0/internal/platform/platform.go:41 +0x2d
oras.land/oras-go/v2/internal/platform.SelectManifest({_, _}, {_, _}, {{0xc00002e0c0, 0x27}, {0xc000032050, 0x47}, 0x292, {0x0, ...}, ...}, ...)
/home/runner/go/pkg/mod/oras.land/oras-go/v2@v2.3.0/internal/platform/platform.go:88 +0x66b
oras.land/oras-go/v2.resolve({0x9782c8, 0xc00020eab0}, {0x977600?, 0xc0000b4370?}, 0x0, {0x7ffd113505b6, 0x6}, {0xc00009c900?, 0xc0001df8c8?})
/home/runner/go/pkg/mod/oras.land/oras-go/v2@v2.3.0/content.go:233 +0x5a6
oras.land/oras-go/v2.Resolve({0x9782c8?, 0xc00020eab0?}, {0x977600?, 0xc0000b4370?}, {0x7ffd113505b6?, 0x8?}, {0xc00009c900?, 0x49fdbc?})
/home/runner/go/pkg/mod/oras.land/oras-go/v2@v2.3.0/content.go:196 +0xc9
oras.land/oras/cmd/oras/root/manifest.fetchManifest({_, _}, {{{0x0, 0x0}}, {0x0, 0x0}, {0x1}, {{0x7ffd113505c8, 0xd}, 0xc00009c900}, ...})
/home/runner/work/oras/oras/cmd/oras/root/manifest/fetch.go:118 +0x27e
oras.land/oras/cmd/oras/root/manifest.fetchCmd.func2(0xc0000b1500?, {0xc0000a0b40?, 0x4?, 0x8b37c3?})
/home/runner/work/oras/oras/cmd/oras/root/manifest/fetch.go:82 +0x5b
github.com/spf13/cobra.(*Command).execute(0xc0001fb500, {0xc0000a0b00, 0x4, 0x4})
/home/runner/go/pkg/mod/github.com/spf13/cobra@v1.7.0/command.go:940 +0x87c
github.com/spf13/cobra.(*Command).ExecuteC(0xc000128300)
/home/runner/go/pkg/mod/github.com/spf13/cobra@v1.7.0/command.go:1068 +0x3a5
github.com/spf13/cobra.(*Command).Execute(...)
/home/runner/go/pkg/mod/github.com/spf13/cobra@v1.7.0/command.go:992
github.com/spf13/cobra.(*Command).ExecuteContext(0x978290?, {0x978450?, 0xc0000a05c0?})
/home/runner/go/pkg/mod/github.com/spf13/cobra@v1.7.0/command.go:985 +0x47
main.main()
/home/runner/work/oras/oras/cmd/oras/main.go:29 +0x96
What happened in your environment?
If I baked an index containing a manifest without platform information and tried to use
oras manifest fetch --platform, then the execution will painc.What did you expect to happen?
The execution should fail with errors like
How can we reproduce it?
What is the version of your ORAS CLI?
v1.1.0
What is your OS environment?
20.04
Are you willing to submit PRs to fix it?