From 57fd5ee6e49e59e814dc0e401c0cc931201f8172 Mon Sep 17 00:00:00 2001 From: Payton Yao Date: Sat, 15 Mar 2025 05:49:57 +0800 Subject: [PATCH] Stop all signals from being reported at MLE --- data/solutions/compile-error.cpp | 22 ++++++++++++++++++++++ data/solutions/runtime-error.cpp | 7 +++++++ data/solutions/wrong-answer.cpp | 5 +++++ src/common/utils/guards.ts | 4 ++++ src/server/evaluation/judge_utils.ts | 8 +++++++- 5 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 data/solutions/compile-error.cpp create mode 100644 data/solutions/runtime-error.cpp create mode 100644 data/solutions/wrong-answer.cpp diff --git a/data/solutions/compile-error.cpp b/data/solutions/compile-error.cpp new file mode 100644 index 00000000..75c5667d --- /dev/null +++ b/data/solutions/compile-error.cpp @@ -0,0 +1,22 @@ +#include +#include +#include +#include + +using namespace std; + +int solve() { + vector> pairs; + int a, b, c; + cin >> a >> b >> c; + cout << a / 0 << endl; + pairs.push_back(make_pair(a, "Alvin")); + pairs.push_back(make_pair(b, "Berto")); + pairs.push_back(make_pair(c, "Carlo")); + sort(pairs.begin(), pairs.end()); + cout << pairs[2].second << endl; +} + +int main() { + solve2(); +} diff --git a/data/solutions/runtime-error.cpp b/data/solutions/runtime-error.cpp new file mode 100644 index 00000000..728eaa5b --- /dev/null +++ b/data/solutions/runtime-error.cpp @@ -0,0 +1,7 @@ +#include +#include + +int main() { + assert(5 > 5); + printf("Done\n"); +} diff --git a/data/solutions/wrong-answer.cpp b/data/solutions/wrong-answer.cpp new file mode 100644 index 00000000..e1a06c3e --- /dev/null +++ b/data/solutions/wrong-answer.cpp @@ -0,0 +1,5 @@ +#include + +int main() { + printf("Wrong answer!!!111!\n"); +} diff --git a/src/common/utils/guards.ts b/src/common/utils/guards.ts index e62eaae4..cc9742d3 100644 --- a/src/common/utils/guards.ts +++ b/src/common/utils/guards.ts @@ -1,3 +1,7 @@ export function notNull(x: T | null): x is T { return x != null; } + +export function isInteger(str: string): boolean { + return /^\d+$/.test(str); +} diff --git a/src/server/evaluation/judge_utils.ts b/src/server/evaluation/judge_utils.ts index 924b69bf..cb95d350 100644 --- a/src/server/evaluation/judge_utils.ts +++ b/src/server/evaluation/judge_utils.ts @@ -2,6 +2,7 @@ import fs from "fs"; import ChildProcess from "child_process"; import { Verdict } from "common/types/constants"; import { ContestantScript, JudgeTaskBatch, JudgeTaskCommunication } from "common/types/judge"; +import { isInteger } from "common/utils/guards"; import { IsolateResult } from "./types"; import { LANGUAGE_SPECS } from "./judge_compile"; import { @@ -14,6 +15,7 @@ import { export const ISOLATE_BIN = "/usr/local/bin/isolate"; const ISOLATE_DIRECTORY = "/var/local/lib/isolate"; +const SIGSEGV = 11; // Signal number for segmentation fault export type IsolateInstance = { name: string; @@ -91,7 +93,11 @@ export class IsolateUtils { } else if (status === "RE") { result.verdict = Verdict.RuntimeError; } else if (status === "SG") { - result.verdict = Verdict.MemoryLimitExceeded; + if (exitsig != null && isInteger(exitsig) && +exitsig === SIGSEGV) { + result.verdict = Verdict.MemoryLimitExceeded; + } else { + result.verdict = Verdict.RuntimeError; + } } else if (exitcode === "0") { result.verdict = Verdict.Accepted; }