Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions db/app_uoj233.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
Expand Down Expand Up @@ -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`),
Expand Down Expand Up @@ -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,
Expand Down
34 changes: 21 additions & 13 deletions judger/judge_client
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import shutil

import traceback
import time
from contextlib import closing
from contextlib import ExitStack, closing

import requests

Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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"]
Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion judger/uoj_judger/include/uoj_judger.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions judger/uoj_judger/include/uoj_judger_v2.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down
12 changes: 6 additions & 6 deletions judger/uoj_judger/run/run_program.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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 << ".";
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions web/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
18 changes: 16 additions & 2 deletions web/app/controllers/download.php
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -44,4 +58,4 @@
header("X-Sendfile: $file_name");
header("Content-type: $mimetype");
header("Content-Disposition: attachment; filename=$download_name");
?>
?>
2 changes: 1 addition & 1 deletion web/app/controllers/judge/download.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion web/app/controllers/problem.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ function(response_text) {custom_test_onsubmit(response_text, $('#div-custom_test
?>
<div class="row d-flex justify-content-center">
<span class="badge badge-secondary mr-1">时间限制:<?=$time_limit!=null?"$time_limit s":"N/A"?></span>
<span class="badge badge-secondary mr-1">空间限制:<?=$memory_limit!=null?"$memory_limit MB":"N/A"?></span>
<span class="badge badge-secondary mr-1">空间限制:<?=$memory_limit!=null?"$memory_limit MiB":"N/A"?></span>
</div>
<div class="float-right">
<?= getClickZanBlock('P', $problem['id'], $problem['zan']) ?>
Expand Down
19 changes: 14 additions & 5 deletions web/app/controllers/problem_data_manage.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ function echoFilePre($file_name) {

$info_form = new UOJForm('info');
$http_host = HTML::escape(UOJContext::httpHost());
$download_url = HTML::url("/download.php?type=problem&id={$problem['id']}");
$download_url = HTML::url("/download/problem/{$problem['id']}/attachment.zip");
$full_download_url = HTML::url("/download/problem/{$problem['id']}/main.zip");
$info_form->appendHTML(<<<EOD
<div class="form-group row">
<!--<label class="col-sm-3 control-label">zip上传数据</label>
Expand All @@ -134,10 +135,18 @@ function echoFilePre($file_name) {
);
$info_form->appendHTML(<<<EOD
<div class="form-group row">
<label class="col-sm-3 control-label">problem_{$problem['id']}.zip</label>
<label class="col-sm-3 control-label">附件/样例包</label>
<div class="col-sm-9">
<div class="form-control-static">
<a href="$download_url">$download_url</a>
<a href="$download_url">problem-{$problem['id']}-attachment.zip</a>
</div>
</div>
</div>
<div class="form-group row">
<label class="col-sm-3 control-label">完整数据包</label>
<div class="col-sm-9">
<div class="form-control-static">
<a href="$full_download_url">problem-{$problem['id']}-main.zip</a>
</div>
</div>
</div>
Expand Down Expand Up @@ -464,10 +473,10 @@ function($self) use ($problem_conf, $allow_files, $n_tests, $n_ex_tests) {

$hackable_form = new UOJForm('hackable');
$hackable_form->handle = function() {
global $problem;
global $problem, $myUser;
$problem['hackable'] = !$problem['hackable'];
//$problem['hackable'] = 0;
$ret = dataSyncProblemData($problem);
$ret = dataSyncProblemData($problem, $myUser);
if ($ret) {
becomeMsgPage('<div>' . $ret . '</div><a href="/problem/'.$problem['id'].'/manage/data">返回</a>');
}
Expand Down
15 changes: 8 additions & 7 deletions web/app/libs/uoj-data-lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,16 @@ function dataClearProblemData($problem) {
}

class SyncProblemDataHandler {
private $problem, $user;
private $problem, $user, $allow_nonbuiltin_judger;
private $upload_dir, $data_dir, $prepare_dir;
private $requirement, $problem_extra_config;
private $problem_conf, $final_problem_conf;
private $allow_files;

public function __construct($problem, $user) {
public function __construct($problem, $user, $allow_nonbuiltin_judger = false) {
$this->problem = $problem;
$this->user = $user;
$this->allow_nonbuiltin_judger = $allow_nonbuiltin_judger;
}

private function check_conf_on($name) {
Expand Down Expand Up @@ -308,7 +309,7 @@ public function handle() {
$this->requirement[] = array('name' => 'answer', 'type' => 'source code', 'file_name' => 'answer.code');
}
} else {
if (!isSuperUser($this->user)) {
if (!$this->allow_nonbuiltin_judger && !isSuperUser($this->user)) {
throw new UOJProblemConfException("use_builtin_judger must be on.");
} else {
foreach ($this->allow_files as $file_name => $file_num) {
Expand Down Expand Up @@ -350,10 +351,10 @@ public function handle() {
}
}

function dataSyncProblemData($problem, $user = null) {
return (new SyncProblemDataHandler($problem, $user))->handle();
function dataSyncProblemData($problem, $user = null, $allow_nonbuiltin_judger = false) {
return (new SyncProblemDataHandler($problem, $user, $allow_nonbuiltin_judger))->handle();
}
function dataAddExtraTest($problem, $input_file_name, $output_file_name) {
function dataAddExtraTest($problem, $input_file_name, $output_file_name, $user = null) {
$id = $problem['id'];

$cur_dir = "/var/uoj_data/upload/$id";
Expand All @@ -371,7 +372,7 @@ function dataAddExtraTest($problem, $input_file_name, $output_file_name) {
move_uploaded_file($input_file_name, "$cur_dir/$new_input_name");
move_uploaded_file($output_file_name, "$cur_dir/$new_output_name");

if (dataSyncProblemData($problem) === '') {
if (dataSyncProblemData($problem, $user, true) === '') {
rejudgeProblemAC($problem);
} else {
error_log('hack successfully but sync failed.');
Expand Down
2 changes: 1 addition & 1 deletion web/app/libs/uoj-form-lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,7 @@ function newSubmissionForm($form_name, $requirement, $zip_file_name_gen, $handle
if ($stat['size'] > $max_size * 1024) {
$zip_file->close();
unlink(UOJContext::storagePath().$zip_file_name);
becomeMsgPage("源代码长度不能超过 {$max_size}KB。");
becomeMsgPage("源代码长度不能超过 {$max_size}KiB。");
}
}

Expand Down
10 changes: 5 additions & 5 deletions web/app/libs/uoj-html-lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ function echoSubmission($submission, $config, $user) {
$used_memory_str = "/";
} else {
$used_time_str = $submission['used_time'] . 'ms';
$used_memory_str = $submission['used_memory'] . 'kb';
$used_memory_str = $submission['used_memory'] . 'KiB';
}

$status = explode(', ', $submission['status'])[0];
Expand Down Expand Up @@ -260,9 +260,9 @@ function echoSubmission($submission, $config, $user) {
echo '<td>', '<a href="/submission/', $submission['id'], '">', $submission['language'], '</a>', '</td>';

if ($submission['tot_size'] < 1024) {
$size_str = $submission['tot_size'] . 'b';
$size_str = $submission['tot_size'] . 'B';
} else {
$size_str = sprintf("%.1f", $submission['tot_size'] / 1024) . 'kb';
$size_str = sprintf("%.1f", $submission['tot_size'] / 1024) . 'KiB';
}
echo '<td>', $size_str, '</td>';

Expand Down Expand Up @@ -718,7 +718,7 @@ private function _print($node) {

echo '<div class="col-sm-3">';
if ($test_memory >= 0) {
echo 'memory: ', $test_memory, 'kb';
echo 'memory: ', $test_memory, 'KiB';
}
echo '</div>';

Expand Down Expand Up @@ -771,7 +771,7 @@ private function _print($node) {

echo '<div class="col-sm-3">';
if ($test_memory >= 0) {
echo 'memory: ', $test_memory, 'kb';
echo 'memory: ', $test_memory, 'KiB';
}
echo '</div>';

Expand Down
8 changes: 6 additions & 2 deletions web/app/models/Upgrader.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@ public static function upgraderRoot() {
}

public static function runSQL($filename) {
passthru('mysql '.escapeshellarg(UOJConfig::$data['database']['database'])
.' -u '.escapeshellarg(UOJConfig::$data['database']['username'])
$cmd = 'mysql';
if (isset(UOJConfig::$data['database']['host'])) {
$cmd .= ' -h '.escapeshellarg(UOJConfig::$data['database']['host']);
}
passthru($cmd.' -u '.escapeshellarg(UOJConfig::$data['database']['username'])
.' --password='.escapeshellarg(UOJConfig::$data['database']['password'])
.' '.escapeshellarg(UOJConfig::$data['database']['database'])
.'<'.escapeshellarg($filename), $ret);
if ($ret !== 0) {
die("run sql failed: ".HTML::escape($filename)."\n");
Expand Down
4 changes: 3 additions & 1 deletion web/app/route.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
Route::any('/problem/{id}/manage/statement', '/problem_statement_manage.php');
Route::any('/problem/{id}/manage/managers', '/problem_managers_manage.php');
Route::any('/problem/{id}/manage/data', '/problem_data_manage.php');
Route::any('/download/problem/{id}/main.zip', '/download.php?type=problem-main-data');
Route::any('/download/problem/{id}/attachment.zip', '/download.php?type=problem');

Route::any('/contests', '/contests.php');
Route::any('/contest/new', '/add_contest.php');
Expand Down Expand Up @@ -78,5 +80,5 @@

Route::post('/judge/download/submission/{id}/{rand_str_id}', '/judge/download.php?type=submission');
Route::post('/judge/download/tmp/{rand_str_id}', '/judge/download.php?type=tmp');
Route::post('/judge/download/problem/{id}', '/judge/download.php?type=problem');
Route::post('/judge/download/problem/{id}', '/judge/download.php?type=problem-main-data');
Route::post('/judge/download/judger', '/judge/download.php?type=judger');
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
ALTER TABLE submissions
MODIFY result BLOB NOT NULL;

ALTER TABLE custom_test_submissions
MODIFY result BLOB NOT NULL;

ALTER TABLE hacks
MODIFY details BLOB NOT NULL;
Loading
Loading