Skip to content

Commit a5cc5c2

Browse files
committed
oci: casext: explicitly disallow negative-size descriptors
This was implicitly allowed by VerifiedReadCloser, and while we have closed that hole it's probably best to provide a more helpful error message. Ref: opencontainers/image-spec#1285 Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
1 parent 114f2af commit a5cc5c2

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

oci/casext/verified_blob.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,27 @@ package casext
2020

2121
import (
2222
"context"
23+
"errors"
24+
"fmt"
2325
"io"
2426

2527
ispec "github.com/opencontainers/image-spec/specs-go/v1"
2628

2729
"github.com/opencontainers/umoci/pkg/hardening"
2830
)
2931

32+
var errInvalidDescriptorSize = errors.New("descriptor size must not be negative")
33+
3034
// GetVerifiedBlob returns a VerifiedReadCloser for retrieving a blob from the
3135
// image, which the caller must Close() *and* read-to-EOF (checking the error
3236
// code of both). Returns ErrNotExist if the digest is not found, and
3337
// ErrBlobDigestMismatch on a mismatched blob digest. In addition, the reader
3438
// is limited to the descriptor.Size.
3539
func (e Engine) GetVerifiedBlob(ctx context.Context, descriptor ispec.Descriptor) (io.ReadCloser, error) {
40+
// Negative sizes are not permitted by the spec, and are a DoS vector.
41+
if descriptor.Size < 0 {
42+
return nil, fmt.Errorf("invalid descriptor: %w", errInvalidDescriptorSize)
43+
}
3644
reader, err := e.GetBlob(ctx, descriptor.Digest)
3745
return &hardening.VerifiedReadCloser{
3846
Reader: reader,

0 commit comments

Comments
 (0)