From 8fb2bc9918aa54bf40a4e6876303da397fa1b746 Mon Sep 17 00:00:00 2001 From: flaryer <30646834+flaryer@users.noreply.github.com> Date: Thu, 23 Dec 2021 12:44:48 +0800 Subject: [PATCH] extend stack size to 64M (#10) * extend stack size to 64M * update version * sync predetect with generateCaseResult --- config.example.toml | 1 - src/Config.ts | 3 --- src/SelfTest/BOMB/STACK.ts | 35 +++++++++++++++++++++++++++++++++++ src/SelfTest/BOMB/index.ts | 2 ++ src/Spawn/Jail.ts | 12 ++++++++++++ src/Spawn/index.ts | 1 + src/Utilities/Judge.ts | 3 ++- src/index.ts | 4 +++- src/version.ts | 1 + 9 files changed, 56 insertions(+), 6 deletions(-) create mode 100644 src/SelfTest/BOMB/STACK.ts create mode 100644 src/version.ts diff --git a/config.example.toml b/config.example.toml index b5ee9a74..eadf21ed 100644 --- a/config.example.toml +++ b/config.example.toml @@ -5,7 +5,6 @@ SecrectKey = "0xffffffff" [self] judgeCapability = 4 name = "TestJudger" -version = "0.0.1" [nsjail] path = "/usr/bin/nsjail" configFile = "./jailConfig.cfg" diff --git a/src/Config.ts b/src/Config.ts index 11496d9e..e497cc4a 100644 --- a/src/Config.ts +++ b/src/Config.ts @@ -83,9 +83,6 @@ export class SelfConfig { @IsNotEmpty() name!: string; @IsString() - @IsNotEmpty() - version!: string; - @IsString() @IsOptional() software?: string; } diff --git a/src/SelfTest/BOMB/STACK.ts b/src/SelfTest/BOMB/STACK.ts new file mode 100644 index 00000000..10dbadf0 --- /dev/null +++ b/src/SelfTest/BOMB/STACK.ts @@ -0,0 +1,35 @@ +import { JudgeResultKind } from "heng-protocol"; +import { generateNormalSelfTest } from "../util"; + +const input = ` +`; +const output = `67108864 +67108864 +`; +const usrCode = ` +#include +#include +int main(void) +{ + struct rlimit r; + if (getrlimit(RLIMIT_STACK, &r) < 0) + { + fprintf(stderr, "getrlimit error\\n"); + return 1; + } + printf("%d\\n", r.rlim_cur); + printf("%d\\n", r.rlim_max); + + return 0; +} +`; + +export const BOOMSTACK = generateNormalSelfTest("BOOMSTACK", "c", usrCode, {}, [ + { + type: "direct", + input, + output, + expectResultType: JudgeResultKind.Accepted, + count: false, + }, +]); diff --git a/src/SelfTest/BOMB/index.ts b/src/SelfTest/BOMB/index.ts index 4e3bbf65..0394dc88 100644 --- a/src/SelfTest/BOMB/index.ts +++ b/src/SelfTest/BOMB/index.ts @@ -6,6 +6,7 @@ import { BOMBCTLE } from "./CTLE"; import { BOMBFORKBOMB } from "./FORKBOMB"; import { KILLTIMER } from "./KILLTIMER"; import { BOMBSPJTLE } from "./SPJTLE"; +import { BOOMSTACK } from "./STACK"; export const BOMB = [ BOMBCOLE, @@ -16,4 +17,5 @@ export const BOMB = [ BOMBSPJTLE, BOMBBULL, KILLTIMER, + BOOMSTACK, ]; diff --git a/src/Spawn/Jail.ts b/src/Spawn/Jail.ts index 1dd3f4cf..0942b198 100644 --- a/src/Spawn/Jail.ts +++ b/src/Spawn/Jail.ts @@ -39,6 +39,7 @@ export interface JailSpawnOption { rlimitCPU?: number | RlimitString; // s default 600s rlimitAS?: number | RlimitString; // M default 4096MB rlimitFSIZE?: number | RlimitString; // M default 1MB + rlimitSTACK?: number | RlimitString; // M default soft cwd?: string; env?: { [key: string]: string }; @@ -154,6 +155,17 @@ export function useJail( } } + if (jailOption.rlimitSTACK !== undefined) { + if (typeof jailOption.rlimitSTACK === "number") { + jailArgs.push( + "--rlimit_stack", + Math.ceil(jailOption.rlimitSTACK).toString() + ); + } else { + jailArgs.push("--rlimit_stack", jailOption.rlimitSTACK); + } + } + if (jailOption.cwd) { jailArgs.push("--cwd", path.resolve(jailOption.cwd)); } diff --git a/src/Spawn/index.ts b/src/Spawn/index.ts index dd6c3492..a2ebdf80 100644 --- a/src/Spawn/index.ts +++ b/src/Spawn/index.ts @@ -90,6 +90,7 @@ export function hengSpawn( if (options.fileLimit) { jailOption.rlimitFSIZE = Math.ceil(options.fileLimit / 1024 / 1024); } + jailOption.rlimitSTACK = 64; jailOption.cwd = options.cwd; diff --git a/src/Utilities/Judge.ts b/src/Utilities/Judge.ts index b037f9fb..69fcf819 100644 --- a/src/Utilities/Judge.ts +++ b/src/Utilities/Judge.ts @@ -255,10 +255,11 @@ export abstract class JudgeAgent { userResult: MeterResult, userExec: Executable ): JudgeResultKind | undefined { + const userRunSumTime = userResult.time.usr + userResult.time.sys; if (userResult.signal === 25) { return JudgeResultKind.OutpuLimitExceeded; } else if ( - userResult.time.usr > userExec.limit.runtime.cpuTime || + userRunSumTime > userExec.limit.runtime.cpuTime || (userResult.time.real > userExec.limit.runtime.cpuTime && userResult.returnCode === -1 && userResult.signal === 9) diff --git a/src/index.ts b/src/index.ts index 39fbd2d4..f23e9aa8 100644 --- a/src/index.ts +++ b/src/index.ts @@ -12,6 +12,7 @@ import { ExecTypeArray } from "./Spawn/Language/decl"; import { chownR } from "./Utilities/File"; import { ExitArgs } from "heng-protocol/internal-protocol/ws"; import { stat } from "./Utilities/Statistics"; +import version from "./version"; async function wait(ms: number) { return new Promise((resolve) => setTimeout(() => resolve(null), ms)); @@ -29,6 +30,7 @@ async function main() { }); const logger = getLogger("main"); logger.info("Lunched"); + logger.info(version); try { getConfig(); } catch (e) { @@ -136,7 +138,7 @@ async function main() { config.judgeCapability, os.cpus().length, config.name, - config.version + version ); logger.info(`Token is ${token.token}`); await controller.connectWs(token.token); diff --git a/src/version.ts b/src/version.ts new file mode 100644 index 00000000..cb8c9bc1 --- /dev/null +++ b/src/version.ts @@ -0,0 +1 @@ +export default "0.1.1";