From 04a4a1a553fa816ed2076993c467959ce858a3d7 Mon Sep 17 00:00:00 2001 From: criyle Date: Tue, 16 Jun 2020 16:54:40 -0400 Subject: [PATCH] Add copy out file size limit --- pkg/envexec/file_collect.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pkg/envexec/file_collect.go b/pkg/envexec/file_collect.go index b9d4765..4509f61 100644 --- a/pkg/envexec/file_collect.go +++ b/pkg/envexec/file_collect.go @@ -1,6 +1,7 @@ package envexec import ( + "fmt" "io/ioutil" "os" @@ -24,6 +25,17 @@ func copyOutAndCollect(m Environment, c *Cmd, ptc []pipeCollector) (map[string]f } defer cf.Close() + // check size limit + if c.CopyOutMax != 0 { + stat, err := cf.Stat() + if err != nil { + return err + } + if s := stat.Size(); s > int64(c.CopyOutMax) { + return fmt.Errorf("File %s have size %d exceeded the limit %d", n, s, c.CopyOutMax) + } + } + c, err := ioutil.ReadAll(cf) if err != nil { return err