judge: 测试数据组数过多时拒绝评测

This commit is contained in:
undefined committed 2020-10-30 23:28:00 +08:00
1 parent 1231fb2ce7
commit 13e874d139
6 files changed
+21 -30

No files matched your search

+2 -2
View File
@@ -6,8 +6,8 @@ db_password=$(cat /dev/urandom | head -n 10 | md5sum | head -c 20)
# Basic # Basic
echo "apt-get update" echo "apt-get update"
apt-get -qq update apt-get -qq update
echo "apt-get install curl wget unzip gnupg -y" echo "apt-get install curl wget gnupg -y"
apt-get install -y curl wget unzip gnupg >/dev/null apt-get install -y curl wget gnupg >/dev/null
apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 9DA31620334BD75D9DCB49F368818C72E52529D4 apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 9DA31620334BD75D9DCB49F368818C72E52529D4
echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.0 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-4.0.list echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.0 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-4.0.list
echo "apt-get update" echo "apt-get update"
+1 -1
View File
@@ -1,7 +1,7 @@
{ {
"name": "@hydrooj/hydrojudge", "name": "@hydrooj/hydrojudge",
"bin": "bin/hydrojudge.js", "bin": "bin/hydrojudge.js",
"version": "2.1.14", "version": "2.1.15",
"main": "package.json", "main": "package.json",
"author": "masnn", "author": "masnn",
"repository": "https://github.com/hydro-dev/Hydro.git", "repository": "https://github.com/hydro-dev/Hydro.git",
+3 -1
View File
@@ -293,5 +293,7 @@ export default async function readCases(folder: string, cfg: Record<string, any>
} else if (fs.existsSync(iniConfig)) { } else if (fs.existsSync(iniConfig)) {
config = { ...convertIniConfig(fs.readFileSync(iniConfig).toString()), ...cfg }; config = { ...convertIniConfig(fs.readFileSync(iniConfig).toString()), ...cfg };
} }
return await readYamlCases(folder, config, args); const result = await readYamlCases(folder, config, args);
if (result.count > 100) throw new FormatError('测试数据组数过多,拒绝评测');
return result;
} }
+7 -7
View File
@@ -50,7 +50,7 @@ class JudgeTask {
nextWaiting = []; nextWaiting = [];
constructor(session, request, ws: WebSocket) { constructor(session: VJ4, request, ws: WebSocket) {
this.stat = {}; this.stat = {};
this.stat.receive = new Date(); this.stat.receive = new Date();
this.session = session; this.session = session;
@@ -230,7 +230,7 @@ export default class VJ4 {
return 'unknown'; return 'unknown';
} }
async problemData(domainId: string, pid: string, savePath, retry = 3, next?) { async problemData(domainId: string, pid: string, savePath: string, retry = 3, next?) {
log.info(`Getting problem data: ${this.config.host}/${domainId}/${pid}`); log.info(`Getting problem data: ${this.config.host}/${domainId}/${pid}`);
await this.ensureLogin(); await this.ensureLogin();
if (next) next({ judge_text: '正在同步测试数据,请稍后' }); if (next) next({ judge_text: '正在同步测试数据,请稍后' });
@@ -249,7 +249,7 @@ export default class VJ4 {
fs.ensureDirSync(path.dirname(savePath)); fs.ensureDirSync(path.dirname(savePath));
const zip = new AdmZip(tmpFilePath); const zip = new AdmZip(tmpFilePath);
const entries = zip.getEntries(); const entries = zip.getEntries();
if (entries.length > 1000) throw new FormatError('Too many files'); if (entries.length > 256) throw new FormatError('Too many files');
await new Promise((resolve, reject) => { await new Promise((resolve, reject) => {
zip.extractAllToAsync(savePath, true, (e) => { zip.extractAllToAsync(savePath, true, (e) => {
if (e) reject(e); if (e) reject(e);
@@ -279,7 +279,7 @@ export default class VJ4 {
fs.ensureDirSync(path.dirname(savePath)); fs.ensureDirSync(path.dirname(savePath));
const zip = new AdmZip(tmpFilePath); const zip = new AdmZip(tmpFilePath);
const entries = zip.getEntries(); const entries = zip.getEntries();
if (entries.length > 1000) throw new FormatError('Too many files'); if (entries.length > 256) throw new FormatError('Too many files');
await new Promise((resolve, reject) => { await new Promise((resolve, reject) => {
zip.extractAllToAsync(savePath, true, (e) => { zip.extractAllToAsync(savePath, true, (e) => {
if (e) reject(e); if (e) reject(e);
@@ -319,7 +319,7 @@ export default class VJ4 {
log.info(`[${this.config.host}] 已连接`); log.info(`[${this.config.host}] 已连接`);
} }
async setCookie(cookie) { async setCookie(cookie: string) {
this.config.cookie = cookie; this.config.cookie = cookie;
this.axios = axios.create({ this.axios = axios.create({
baseURL: this.config.server_url, baseURL: this.config.server_url,
@@ -357,7 +357,7 @@ export default class VJ4 {
} }
} }
async processData(folder) { // eslint-disable-line class-methods-use-this async processData(folder: string) { // eslint-disable-line class-methods-use-this
let files = await fs.readdir(folder); let files = await fs.readdir(folder);
let ini = false; let ini = false;
if (files.length <= 2) { if (files.length <= 2) {
@@ -403,7 +403,7 @@ export default class VJ4 {
return filePath; return filePath;
} }
async retry(queue) { async retry(queue: Queue<any>) {
this.consume(queue).catch(() => { this.consume(queue).catch(() => {
setTimeout(() => { setTimeout(() => {
this.retry(queue); this.retry(queue);
+1 -1
View File
@@ -75,7 +75,7 @@ async function postInit() {
fs.ensureDirSync(path.dirname(savePath)); fs.ensureDirSync(path.dirname(savePath));
const zip = new AdmZip(tmpFilePath); const zip = new AdmZip(tmpFilePath);
const entries = zip.getEntries(); const entries = zip.getEntries();
if (entries.length > 1000) throw new FormatError('Too many files'); if (entries.length > 256) throw new FormatError('Too many files');
await new Promise((resolve, reject) => { await new Promise((resolve, reject) => {
zip.extractAllToAsync(savePath, true, (e) => { zip.extractAllToAsync(savePath, true, (e) => {
if (e) reject(e); if (e) reject(e);
@@ -3,30 +3,19 @@ import yaml from 'js-yaml';
function convert(ini: string) { function convert(ini: string) {
const f = ini.split('\n'); const f = ini.split('\n');
const count = parseInt(f[0], 10); const count = parseInt(f[0], 10);
const res = { cases: [] }; const res = { subtasks: [] };
for (let i = 1; i <= count; i++) { for (let i = 1; i <= count; i++) {
const [input, output, time, score, memory] = f[i].split('|'); const [input, output, time, score, memory] = f[i].split('|');
const cur = { const cur = {
input, output, score: parseInt(score, 10), time: `${time}s`, memory: '128m', cases: [{ input: `input/${input}`, output: `output/${output}` }],
score: parseInt(score, 10),
time: `${time}s`,
memory: '128m',
}; };
if (!Number.isNaN(parseInt(memory, 10))) cur.memory = `${Math.floor(parseInt(memory, 10) / 1024)}m`; if (!Number.isNaN(parseInt(memory, 10))) cur.memory = `${Math.floor(parseInt(memory, 10) / 1024)}m`;
res.cases.push(cur); res.subtasks.push(cur);
} }
if (res.cases.length > 0) { return yaml.safeDump(res);
const { time, score, memory } = res.cases[0];
for (let i = 1; i < res.cases.length; i++) {
if (res.cases[i].time !== time
|| res.cases[i].score !== score
|| res.cases[i].memory !== memory) {
return yaml.safeDump(res);
}
}
}
return yaml.safeDump({
time: res.cases[0].time,
score: res.cases[0].score,
memory: res.cases[0].memory,
});
} }
global.Hydro.lib['testdata.convert.ini'] = convert; global.Hydro.lib['testdata.convert.ini'] = convert;