Add copy out file size limit

This commit is contained in:
criyle 2020-06-16 16:54:40 -04:00
parent f4496d38f6
commit 04a4a1a553

View File

@ -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