diff --git a/db/app_uoj233.sql b/db/app_uoj233.sql index b20be870b..2ff302183 100644 --- a/db/app_uoj233.sql +++ b/db/app_uoj233.sql @@ -347,7 +347,7 @@ CREATE TABLE `custom_test_submissions` ( `submitter` varchar(20) NOT NULL, `content` text NOT NULL, `judge_time` datetime DEFAULT NULL, - `result` blob NOT NULL, + `result` longblob NOT NULL, `status` varchar(20) NOT NULL, `status_details` varchar(100) NOT NULL, PRIMARY KEY (`id`) @@ -381,7 +381,7 @@ CREATE TABLE `hacks` ( `submit_time` datetime NOT NULL, `judge_time` datetime DEFAULT NULL, `success` tinyint(1) DEFAULT NULL, - `details` blob NOT NULL, + `details` longblob NOT NULL, `is_hidden` tinyint(1) NOT NULL, PRIMARY KEY (`id`), KEY `submission_id` (`submission_id`), @@ -588,7 +588,7 @@ CREATE TABLE `submissions` ( `language` varchar(15) NOT NULL, `tot_size` int(11) NOT NULL, `judge_time` datetime DEFAULT NULL, - `result` blob NOT NULL, + `result` longblob NOT NULL, `status` varchar(20) NOT NULL, `result_error` varchar(20) DEFAULT NULL, `score` int(11) DEFAULT NULL, diff --git a/judger/judge_client b/judger/judge_client index a9f69487e..7959cadd9 100755 --- a/judger/judge_client +++ b/judger/judge_client @@ -11,7 +11,7 @@ import shutil import traceback import time -from contextlib import closing +from contextlib import ExitStack, closing import requests @@ -284,7 +284,7 @@ def judge(): submission_judged = False report_thread.start() - execute('cd %s && ./main_judger' % (pipes.quote(uoj_judger_path()))) + execute("cd %s && ./main_judger" % (pipes.quote(uoj_judger_path()))) submission_judged = True report_thread.join() @@ -331,16 +331,7 @@ def send_and_fetch(result=None, fetch_new=True): data["is_hack"] = True data["id"] = submission["hack"]["id"] if result != False and result["score"]: - try: - print("succ hack!", file=sys.stderr) - files = { - ("hack_input", open("uoj_judger/work/hack_input.txt", "r")), - ("std_output", open("uoj_judger/work/std_output.txt", "r")), - } - except Exception: - print_judge_client_status() - traceback.print_exc() - result = False + print("succ hack!", file=sys.stderr) elif "is_custom_test" in submission: data["is_custom_test"] = True data["id"] = submission["id"] @@ -354,7 +345,24 @@ def send_and_fetch(result=None, fetch_new=True): while True: try: - ret = uoj_interact(data, files) + if ( + result is not None + and "is_hack" in submission + and result != False + and result["score"] + ): + with ExitStack() as stack: + files = { + "hack_input": stack.enter_context( + open("uoj_judger/work/hack_input.txt", "rb") + ), + "std_output": stack.enter_context( + open("uoj_judger/work/std_output.txt", "rb") + ), + } + ret = uoj_interact(data, files) + else: + ret = uoj_interact(data, files) print(ret) except Exception: print_judge_client_status() diff --git a/judger/uoj_judger/include/uoj_judger.h b/judger/uoj_judger/include/uoj_judger.h index ebf6a847b..719be4a47 100644 --- a/judger/uoj_judger/include/uoj_judger.h +++ b/judger/uoj_judger/include/uoj_judger.h @@ -257,7 +257,7 @@ typedef runp::result RunResult; const RunLimit RL_DEFAULT = RunLimit(1, 256, 64); const RunLimit RL_GENERATOR_DEFAULT = RunLimit(2, 512, 64); -const RunLimit RL_JUDGER_DEFAULT = RunLimit(600, 2048, 128); // 2048 = 2GB. change it if needed +const RunLimit RL_JUDGER_DEFAULT = RunLimit(600, 2048, 128); // 2048 = 2GiB. change it if needed const RunLimit RL_CHECKER_DEFAULT = RunLimit(5, 256, 64); const RunLimit RL_INTERACTOR_DEFAULT = RunLimit(1, 256, 64); const RunLimit RL_VALIDATOR_DEFAULT = RunLimit(5, 256, 64); diff --git a/judger/uoj_judger/include/uoj_judger_v2.h b/judger/uoj_judger/include/uoj_judger_v2.h index cf5a5ca22..bdc766d27 100644 --- a/judger/uoj_judger/include/uoj_judger_v2.h +++ b/judger/uoj_judger/include/uoj_judger_v2.h @@ -287,7 +287,7 @@ bool file_move(const string &a, const string &b) { // move a to b /*====================== parameter ==================== */ const runp::limits_t RL_DEFAULT(1, 256, 64); -const runp::limits_t RL_JUDGER_DEFAULT(600, 10 * 1024, 128); // 10GB. change it if needed +const runp::limits_t RL_JUDGER_DEFAULT(600, 10 * 1024, 128); // 10GiB. change it if needed const runp::limits_t RL_CHECKER_DEFAULT(5, 256, 64); const runp::limits_t RL_INTERACTOR_DEFAULT(1, 256, 64); const runp::limits_t RL_VALIDATOR_DEFAULT(5, 256, 64); @@ -610,7 +610,7 @@ runp::limits_t conf_run_limit(string pre, const int &num, const runp::limits_t & limits.memory = conf_int(pre + "memory_limit", num, val.memory); limits.output = conf_int(pre + "output_limit", num, val.output); limits.real_time = conf_double(pre + "real_time_limit", num, val.real_time); - limits.stack = conf_int(pre + "stack_limit", num, val.real_time); + limits.stack = conf_int(pre + "stack_limit", num, val.stack); return limits; } runp::limits_t conf_run_limit(const int &num, const runp::limits_t &val) { diff --git a/judger/uoj_judger/run/run_program.cpp b/judger/uoj_judger/run/run_program.cpp index 77d0c035d..f11593070 100644 --- a/judger/uoj_judger/run/run_program.cpp +++ b/judger/uoj_judger/run/run_program.cpp @@ -32,9 +32,9 @@ struct run_event { argp_option run_program_argp_options[] = { {"tl", 'T', "TIME_LIMIT", 0, "Set time limit (in second)", 1}, {"rtl", 'R', "TIME_LIMIT", 0, "Set real time limit (in second)", 2}, - {"ml", 'M', "MEMORY_LIMIT", 0, "Set memory limit (in mb)", 3}, - {"ol", 'O', "OUTPUT_LIMIT", 0, "Set output limit (in mb)", 4}, - {"sl", 'S', "STACK_LIMIT", 0, "Set stack limit (in mb)", 5}, + {"ml", 'M', "MEMORY_LIMIT", 0, "Set memory limit (in MiB)", 3}, + {"ol", 'O', "OUTPUT_LIMIT", 0, "Set output limit (in MiB)", 4}, + {"sl", 'S', "STACK_LIMIT", 0, "Set stack limit (in MiB)", 5}, {"in", 'i', "IN", 0, "Set input file name", 6}, {"out", 'o', "OUT", 0, "Set output file name", 7}, {"err", 'e', "ERR", 0, "Set error file name", 8}, @@ -347,7 +347,7 @@ std::string get_usage_summary(struct rusage *rusep) { sout << rusep->ru_utime.tv_sec * 1000 + rusep->ru_utime.tv_usec / 1000 << "ms / "; sout << total_cpu.tv_sec * 1000 + total_cpu.tv_usec / 1000 << "ms / "; sout << elapsed.tv_sec * 1000 + elapsed.tv_usec / 1000 << "ms." << '\n'; - sout << "max RSS: " << rusep->ru_maxrss << "kb." << '\n'; + sout << "max RSS: " << rusep->ru_maxrss << "KiB." << '\n'; sout << "total number of threads: " << total_rp_children + 1 << "." << '\n'; sout << "voluntary / total context switches: " << rusep->ru_nvcsw << " / " << rusep->ru_nvcsw + rusep->ru_nivcsw << "."; @@ -576,11 +576,11 @@ void dispatch_event(run_event &&e) { case ET_MLE: stop_all(runp::result( runp::RS_MLE, - "max RSS >" + std::to_string(run_program_config.limits.memory) + "MB")); + "max RSS >" + std::to_string(run_program_config.limits.memory) + "MiB")); case ET_OLE: stop_all(runp::result(runp::RS_OLE, "output limit exceeded: >" - + std::to_string(run_program_config.limits.output) + "MB")); + + std::to_string(run_program_config.limits.output) + "MiB")); case ET_EXIT: if (run_program_config.need_show_trace_details) { fprintf(stderr, "exit : %d\n", e.exitcode); diff --git a/web/Dockerfile b/web/Dockerfile index 71fd1b8b7..2c5440faf 100644 --- a/web/Dockerfile +++ b/web/Dockerfile @@ -36,6 +36,7 @@ RUN sh web/install.sh -p && \ 'if [ ! -f "/var/uoj_data/.UOJSetupDone" ]; then' \ ' cd /opt/uoj/web && sh install.sh -i' \ 'fi' \ + 'php /opt/uoj/web/app/cli.php upgrade:latest' \ 'apache2ctl -D FOREGROUND' > /opt/up && \ chmod +x /opt/up diff --git a/web/app/controllers/download.php b/web/app/controllers/download.php index 7d735fe9d..e73aa46e5 100644 --- a/web/app/controllers/download.php +++ b/web/app/controllers/download.php @@ -24,7 +24,21 @@ $id = $_GET['id']; $file_name = "/var/uoj_data/$id/download.zip"; - $download_name = "problem_$id.zip"; + $download_name = "problem-$id-attachment.zip"; + break; + case 'problem-main-data': + if (!validateUInt($_GET['id']) || !($problem = queryProblemBrief($_GET['id']))) { + become404Page(); + } + + if (!hasProblemPermission($myUser, $problem)) { + become404Page(); + } + + $id = $_GET['id']; + + $file_name = "/var/uoj_data/$id.zip"; + $download_name = "problem-$id-main.zip"; break; case 'testlib.h': $file_name = "/opt/uoj/judger/uoj_judger/include/testlib.h"; @@ -44,4 +58,4 @@ header("X-Sendfile: $file_name"); header("Content-type: $mimetype"); header("Content-Disposition: attachment; filename=$download_name"); -?> \ No newline at end of file +?> diff --git a/web/app/controllers/judge/download.php b/web/app/controllers/judge/download.php index 6358ccd9a..bb386b46f 100644 --- a/web/app/controllers/judge/download.php +++ b/web/app/controllers/judge/download.php @@ -14,7 +14,7 @@ $file_name = UOJContext::storagePath()."/tmp/{$_GET['rand_str_id']}"; $download_name = "tmp"; break; - case 'problem': + case 'problem-main-data': $id = $_GET['id']; if (!validateUInt($id) || !($problem = queryProblemBrief($id))) { become404Page(); diff --git a/web/app/controllers/problem.php b/web/app/controllers/problem.php index f2ce2abb6..74ddd8919 100644 --- a/web/app/controllers/problem.php +++ b/web/app/controllers/problem.php @@ -214,7 +214,7 @@ function(response_text) {custom_test_onsubmit(response_text, $('#div-custom_test ?>