From c747d9f8eef42630de7330349ed74955d3c0f5c3 Mon Sep 17 00:00:00 2001 From: Brian Goff Date: Mon, 12 Oct 2020 18:08:28 +0000 Subject: [PATCH] pull: Validate layer digest format Otherwise a malformed or empty digest may cause a panic. Signed-off-by: Brian Goff (cherry picked from commit a7d4af84bd2f189b921c3ec60796aa825e3a0f2a) Signed-off-by: Sebastiaan van Stijn --- builder/builder-next/adapters/containerimage/pull.go | 3 +++ distribution/pull_v2.go | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/builder/builder-next/adapters/containerimage/pull.go b/builder/builder-next/adapters/containerimage/pull.go index 733a337e87..e731e3e143 100644 --- a/builder/builder-next/adapters/containerimage/pull.go +++ b/builder/builder-next/adapters/containerimage/pull.go @@ -524,6 +524,9 @@ func (p *puller) Snapshot(ctx context.Context, g session.Group) (cache.Immutable layers := make([]xfer.DownloadDescriptor, 0, len(mfst.Layers)) for i, desc := range mfst.Layers { + if err := desc.Digest.Validate(); err != nil { + return nil, errors.Wrap(err, "layer digest could not be validated") + } ongoing.add(desc) layers = append(layers, &layerDescriptor{ desc: desc, diff --git a/distribution/pull_v2.go b/distribution/pull_v2.go index 12497ea890..023ee2e71e 100644 --- a/distribution/pull_v2.go +++ b/distribution/pull_v2.go @@ -528,6 +528,9 @@ func (p *v2Puller) pullSchema1(ctx context.Context, ref reference.Reference, unv // to top-most, so that the downloads slice gets ordered correctly. for i := len(verifiedManifest.FSLayers) - 1; i >= 0; i-- { blobSum := verifiedManifest.FSLayers[i].BlobSum + if err = blobSum.Validate(); err != nil { + return "", "", errors.Wrapf(err, "could not validate layer digest %q", blobSum) + } var throwAway struct { ThrowAway bool `json:"throwaway,omitempty"` @@ -626,6 +629,9 @@ func (p *v2Puller) pullSchema2Layers(ctx context.Context, target distribution.De // Note that the order of this loop is in the direction of bottom-most // to top-most, so that the downloads slice gets ordered correctly. for _, d := range layers { + if err := d.Digest.Validate(); err != nil { + return "", errors.Wrapf(err, "could not validate layer digest %q", d.Digest) + } layerDescriptor := &v2LayerDescriptor{ digest: d.Digest, repo: p.repo,