Skip to content

Commit 5d1ae9c

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. Not blocking this earlier was mostly due to a somewhat overly-permissive reading of the discussion in opencontainers/image-spec#153 which was finally clarified in opencontainers/image-spec#1285. Unknown sizes are a classic DoS vector, so allowing them (especially for descriptors where it makes little sense to have an unknown size) seems like a bad idea in general. Ref: opencontainers/image-spec#1285 Signed-off-by: Aleksa Sarai <[email protected]>
1 parent 9f426d3 commit 5d1ae9c

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1919
the `manifests` entry to `null` (which was technically a violation of the
2020
specification, though such images cannot be pushed or interacted with outside
2121
of umoci).
22+
* Based on [some recent developments in the image-spec][image-spec#1285], umoci
23+
will now produce an error if it encounters descriptors with a negative size
24+
(this was a potential DoS vector previously) as well as a theoretical attack
25+
where an attacker would endlessly write to a blob (this would not be
26+
generally exploitable for images with descriptors).
2227

2328
### Changed ###
2429
* We now use `go:embed` to fill the version information of `umoci --version`,
@@ -33,6 +38,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
3338
(and after that, we may choose to keep the `jq`-based validators as a
3439
double-check that our own validators are working correctly).
3540

41+
[image-spec#1285]: https://github.com/opencontainers/image-spec/pull/1285
3642
[docker-library/meta-scripts]: https://github.com/docker-library/meta-scripts
3743

3844
## [0.5.0] - 2025-05-21 ##

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)