|
@@ -7,6 +7,7 @@ import (
|
|
"io"
|
|
"io"
|
|
"os"
|
|
"os"
|
|
"runtime"
|
|
"runtime"
|
|
|
|
+ "strings"
|
|
"time"
|
|
"time"
|
|
|
|
|
|
"github.com/containerd/containerd/log"
|
|
"github.com/containerd/containerd/log"
|
|
@@ -606,6 +607,21 @@ func (p *puller) pullSchema1(ctx context.Context, ref reference.Reference, unver
|
|
return imageID, manifestDigest, nil
|
|
return imageID, manifestDigest, nil
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+func checkSupportedMediaType(mediaType string) error {
|
|
|
|
+ supportedMediaTypes := []string{
|
|
|
|
+ "application/vnd.oci.image.",
|
|
|
|
+ "application/vnd.docker.",
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ lowerMt := strings.ToLower(mediaType)
|
|
|
|
+ for _, mt := range supportedMediaTypes {
|
|
|
|
+ if strings.HasPrefix(lowerMt, mt) {
|
|
|
|
+ return nil
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return unsupportedMediaTypeError{MediaType: mediaType}
|
|
|
|
+}
|
|
|
|
+
|
|
func (p *puller) pullSchema2Layers(ctx context.Context, target distribution.Descriptor, layers []distribution.Descriptor, platform *specs.Platform) (id digest.Digest, err error) {
|
|
func (p *puller) pullSchema2Layers(ctx context.Context, target distribution.Descriptor, layers []distribution.Descriptor, platform *specs.Platform) (id digest.Digest, err error) {
|
|
if _, err := p.config.ImageStore.Get(ctx, target.Digest); err == nil {
|
|
if _, err := p.config.ImageStore.Get(ctx, target.Digest); err == nil {
|
|
// If the image already exists locally, no need to pull
|
|
// If the image already exists locally, no need to pull
|
|
@@ -613,6 +629,10 @@ func (p *puller) pullSchema2Layers(ctx context.Context, target distribution.Desc
|
|
return target.Digest, nil
|
|
return target.Digest, nil
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ if err := checkSupportedMediaType(target.MediaType); err != nil {
|
|
|
|
+ return "", err
|
|
|
|
+ }
|
|
|
|
+
|
|
var descriptors []xfer.DownloadDescriptor
|
|
var descriptors []xfer.DownloadDescriptor
|
|
|
|
|
|
// Note that the order of this loop is in the direction of bottom-most
|
|
// Note that the order of this loop is in the direction of bottom-most
|
|
@@ -621,6 +641,9 @@ func (p *puller) pullSchema2Layers(ctx context.Context, target distribution.Desc
|
|
if err := d.Digest.Validate(); err != nil {
|
|
if err := d.Digest.Validate(); err != nil {
|
|
return "", errors.Wrapf(err, "could not validate layer digest %q", d.Digest)
|
|
return "", errors.Wrapf(err, "could not validate layer digest %q", d.Digest)
|
|
}
|
|
}
|
|
|
|
+ if err := checkSupportedMediaType(d.MediaType); err != nil {
|
|
|
|
+ return "", err
|
|
|
|
+ }
|
|
layerDescriptor := &layerDescriptor{
|
|
layerDescriptor := &layerDescriptor{
|
|
digest: d.Digest,
|
|
digest: d.Digest,
|
|
repo: p.repo,
|
|
repo: p.repo,
|