mirror of
https://github.com/criyle/go-judge.git
synced 2025-11-04 14:50:02 +08:00
Add copy out file size limit
This commit is contained in:
parent
f4496d38f6
commit
04a4a1a553
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user