From e92dd4dd5d5499626c2ac648aaef5b4ca2ed6836 Mon Sep 17 00:00:00 2001 From: Jaehyeon Kim Date: Sat, 7 Dec 2024 17:19:08 +0900 Subject: [PATCH] feat(iris): limit judge result output (#2256) * feat(iris): limit judge result output * feat(iris): set limit 1MB --- apps/iris/src/common/constants/constants.go | 2 ++ apps/iris/src/handler/judge-handler.go | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/apps/iris/src/common/constants/constants.go b/apps/iris/src/common/constants/constants.go index 0aae1ce8cc..dccb337ead 100644 --- a/apps/iris/src/common/constants/constants.go +++ b/apps/iris/src/common/constants/constants.go @@ -53,3 +53,5 @@ const ( EXCHANGE = "judger-exchange" RESULT_KEY = "result" ) + +const MAX_OUTPUT = 1048576 // 1MB diff --git a/apps/iris/src/handler/judge-handler.go b/apps/iris/src/handler/judge-handler.go index 547ca24afc..14241b1435 100644 --- a/apps/iris/src/handler/judge-handler.go +++ b/apps/iris/src/handler/judge-handler.go @@ -347,6 +347,10 @@ func (j *JudgeHandler) judgeTestcase(idx int, dir string, validReq *Request, res.SetJudgeExecResult(runResult.ExecResult) res.Output = string(runResult.Output) + if len(res.Output) > constants.MAX_OUTPUT { + res.Output = res.Output[:constants.MAX_OUTPUT] + } + if runResult.ExecResult.ResultCode != sandbox.RUN_SUCCESS { res.SetJudgeResultCode(SandboxResultCodeToJudgeResultCode(runResult.ExecResult.ResultCode)) goto Send