1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

pull: Validate layer digest format

Otherwise a malformed or empty digest may cause a panic.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
(cherry picked from commit a7d4af84bd)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Brian Goff 2020-10-12 18:08:28 +00:00 committed by Sebastiaan van Stijn
parent 3e0025e2fc
commit c747d9f8ee
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C
2 changed files with 9 additions and 0 deletions

View file

@ -524,6 +524,9 @@ func (p *puller) Snapshot(ctx context.Context, g session.Group) (cache.Immutable
layers := make([]xfer.DownloadDescriptor, 0, len(mfst.Layers)) layers := make([]xfer.DownloadDescriptor, 0, len(mfst.Layers))
for i, desc := range 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) ongoing.add(desc)
layers = append(layers, &layerDescriptor{ layers = append(layers, &layerDescriptor{
desc: desc, desc: desc,

View file

@ -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. // to top-most, so that the downloads slice gets ordered correctly.
for i := len(verifiedManifest.FSLayers) - 1; i >= 0; i-- { for i := len(verifiedManifest.FSLayers) - 1; i >= 0; i-- {
blobSum := verifiedManifest.FSLayers[i].BlobSum 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 { var throwAway struct {
ThrowAway bool `json:"throwaway,omitempty"` 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 // 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. // to top-most, so that the downloads slice gets ordered correctly.
for _, d := range layers { 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{ layerDescriptor := &v2LayerDescriptor{
digest: d.Digest, digest: d.Digest,
repo: p.repo, repo: p.repo,