Skip to content

Commit

Permalink
limit layer size
Browse files Browse the repository at this point in the history
Signed-off-by: tomersein <[email protected]>
  • Loading branch information
tomersein committed Nov 30, 2024
1 parent e051cfd commit ee31ef8
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions cmd/syft/internal/options/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@ type sourceConfig struct {
}

type fileSource struct {
Digests []string `json:"digests" yaml:"digests" mapstructure:"digests"`
MaxLayerSize string `json:"max-layer-size" yaml:"max-layer-size" mapstructure:"max-layer-size"`
Digests []string `json:"digests" yaml:"digests" mapstructure:"digests"`
}

var _ interface {
clio.FieldDescriber
} = (*sourceConfig)(nil)

var _ clio.PostLoader = (*imageSource)(nil)

func (o *sourceConfig) DescribeFields(descriptions clio.FieldDescriptionSet) {
descriptions.Add(&o.File.Digests, `the file digest algorithms to use on the scanned file (options: "md5", "sha1", "sha224", "sha256", "sha384", "sha512")`)
descriptions.Add(&o.Image.DefaultPullSource, `allows users to specify which image source should be used to generate the sbom
Expand All @@ -38,6 +39,7 @@ valid values are: registry, docker, podman`)

type imageSource struct {
DefaultPullSource string `json:"default-pull-source" yaml:"default-pull-source" mapstructure:"default-pull-source"`
MaxLayerSize string `json:"max-layer-size" yaml:"max-layer-size" mapstructure:"max-layer-size"`
}

func defaultSourceConfig() sourceConfig {
Expand All @@ -56,17 +58,17 @@ func (c *fileSource) PostLoad() error {
digests := strset.New(c.Digests...).List()
sort.Strings(digests)
c.Digests = digests
return nil
}

func (c *imageSource) PostLoad() error {
if c.MaxLayerSize != "" {
perFileReadLimit, err := humanize.ParseBytes(c.MaxLayerSize)
if err != nil {
return err
}
stereoscopeFile.SetPerFileReadLimit(int64(perFileReadLimit))
}
return nil
}

func (c imageSource) PostLoad() error {
return checkDefaultSourceValues(c.DefaultPullSource)
}

Expand Down

0 comments on commit ee31ef8

Please sign in to comment.