Skip to content

Commit

Permalink
Update bundle reader to cap buffer size
Browse files Browse the repository at this point in the history
This was tested manually.

Fixes open-policy-agent#920

Signed-off-by: Torin Sandall <torinsandall@gmail.com>
  • Loading branch information
tsandall committed Sep 4, 2018
1 parent b4e9362 commit bdbfcc1
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion bundle/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ const (
DataFileExt = "/data.json"
)

const bundleLimitBytes = (1024 * 1024 * 1024) + 1 // limit bundle reads to 1GB to protect against gzip bombs

// Bundle represents a loaded bundle. The bundle can contain data and policies.
type Bundle struct {
Manifest Manifest
Expand Down Expand Up @@ -118,7 +120,13 @@ func Read(r io.Reader) (Bundle, error) {
}

var buf bytes.Buffer
io.Copy(&buf, tr)
n, err := io.CopyN(&buf, tr, bundleLimitBytes)
if err != nil && err != io.EOF {
return bundle, err
} else if err == nil && n >= bundleLimitBytes {
return bundle, fmt.Errorf("bundle exceeded max size (%v bytes)", bundleLimitBytes-1)
}

path := header.Name

if strings.HasSuffix(path, RegoExt) {
Expand Down

0 comments on commit bdbfcc1

Please sign in to comment.