Skip to content

Commit

Permalink
chunked: refactor value into const
Browse files Browse the repository at this point in the history
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
  • Loading branch information
giuseppe committed Nov 14, 2024
1 parent 28bd89e commit e1238b6
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions pkg/chunked/compression_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ import (
expMaps "golang.org/x/exp/maps"
)

const (
// maxTocSize is the maximum size of a blob that we will attempt to process.
// It is used to prevent DoS attacks from layers that embed a very large TOC file.
maxTocSize = (1 << 20) * 50
)

var typesToTar = map[string]byte{
TypeReg: tar.TypeReg,
TypeLink: tar.TypeLink,
Expand Down Expand Up @@ -77,7 +83,7 @@ func readEstargzChunkedManifest(blobStream ImageSourceSeekable, blobSize int64,

size := int64(blobSize - footerSize - tocOffset)
// set a reasonable limit
if size > (1<<20)*50 {
if size > maxTocSize {
return nil, 0, errors.New("manifest too big")
}

Expand Down Expand Up @@ -106,7 +112,7 @@ func readEstargzChunkedManifest(blobStream ImageSourceSeekable, blobSize int64,
return err
}
// set a reasonable limit
if header.Size > (1<<20)*50 {
if header.Size > maxTocSize {
return errors.New("manifest too big")
}

Expand Down Expand Up @@ -166,10 +172,10 @@ func readZstdChunkedManifest(blobStream ImageSourceSeekable, tocDigest digest.Di
}

// set a reasonable limit
if manifestChunk.Length > (1<<20)*50 {
if manifestChunk.Length > maxTocSize {
return nil, nil, nil, 0, errors.New("manifest too big")
}
if manifestLengthUncompressed > (1<<20)*50 {
if manifestLengthUncompressed > maxTocSize {
return nil, nil, nil, 0, errors.New("manifest too big")
}

Expand Down

0 comments on commit e1238b6

Please sign in to comment.