diff --git a/registry/storage/manifestlisthandler.go b/registry/storage/manifestlisthandler.go index 085ccccc2..43468f669 100644 --- a/registry/storage/manifestlisthandler.go +++ b/registry/storage/manifestlisthandler.go @@ -64,6 +64,10 @@ func (ms *manifestListHandler) Put(ctx context.Context, manifestList distributio func (ms *manifestListHandler) verifyManifest(ctx context.Context, mnfst manifestlist.DeserializedManifestList, skipDependencyVerification bool) error { var errs distribution.ErrManifestVerification + if mnfst.SchemaVersion != 2 { + return fmt.Errorf("unrecognized manifest list schema version %d", mnfst.SchemaVersion) + } + if !skipDependencyVerification { // This manifest service is different from the blob service // returned by Blob. It uses a linked blob store to ensure that diff --git a/registry/storage/manifeststore_test.go b/registry/storage/manifeststore_test.go index 7c9b9edf8..6c6cf9051 100644 --- a/registry/storage/manifeststore_test.go +++ b/registry/storage/manifeststore_test.go @@ -424,9 +424,22 @@ func testOCIManifestStorage(t *testing.T, testname string, includeMediaTypes boo t.Fatalf("%s: unexpected error generating manifest: %v", testname, err) } + // before putting the manifest test for proper handling of SchemaVersion + + if manifest.(*ocischema.DeserializedManifest).Manifest.SchemaVersion != 2 { + t.Fatalf("%s: unexpected error generating default version for oci manifest", testname) + } + manifest.(*ocischema.DeserializedManifest).Manifest.SchemaVersion = 0 + var manifestDigest digest.Digest if manifestDigest, err = ms.Put(ctx, manifest); err != nil { - t.Fatalf("%s: unexpected error putting manifest: %v", testname, err) + if err.Error() != "unrecognized manifest schema version 0" { + t.Fatalf("%s: unexpected error putting manifest: %v", testname, err) + } + manifest.(*ocischema.DeserializedManifest).Manifest.SchemaVersion = 2 + if manifestDigest, err = ms.Put(ctx, manifest); err != nil { + t.Fatalf("%s: unexpected error putting manifest: %v", testname, err) + } } // Also create an image index that contains the manifest diff --git a/registry/storage/ocimanifesthandler.go b/registry/storage/ocimanifesthandler.go index 57ff28290..03264b8cc 100644 --- a/registry/storage/ocimanifesthandler.go +++ b/registry/storage/ocimanifesthandler.go @@ -66,6 +66,10 @@ func (ms *ocischemaManifestHandler) Put(ctx context.Context, manifest distributi func (ms *ocischemaManifestHandler) verifyManifest(ctx context.Context, mnfst ocischema.DeserializedManifest, skipDependencyVerification bool) error { var errs distribution.ErrManifestVerification + if mnfst.Manifest.SchemaVersion != 2 { + return fmt.Errorf("unrecognized manifest schema version %d", mnfst.Manifest.SchemaVersion) + } + if skipDependencyVerification { return nil } diff --git a/registry/storage/schema2manifesthandler.go b/registry/storage/schema2manifesthandler.go index b0ae01ae1..863ab2ba2 100644 --- a/registry/storage/schema2manifesthandler.go +++ b/registry/storage/schema2manifesthandler.go @@ -73,6 +73,10 @@ func (ms *schema2ManifestHandler) Put(ctx context.Context, manifest distribution func (ms *schema2ManifestHandler) verifyManifest(ctx context.Context, mnfst schema2.DeserializedManifest, skipDependencyVerification bool) error { var errs distribution.ErrManifestVerification + if mnfst.Manifest.SchemaVersion != 2 { + return fmt.Errorf("unrecognized manifest schema version %d", mnfst.Manifest.SchemaVersion) + } + if skipDependencyVerification { return nil }