judge: key check report

This commit is contained in:
undefined committed 2021-09-21 23:21:22 +08:00
1 parent cf4ef57f68
commit 132ef0312c
14 files changed
+38 -25

No files matched your search

+11 -7
View File
@@ -402,21 +402,25 @@ export class ProblemFilesHandler extends ProblemDetailHandler {
@post('filename', Types.Name, true)
@post('type', Types.Range(['testdata', 'additional_file']), true)
async postUploadFile(domainId: string, filename: string, type = 'testdata') {
if ((this.pdoc.data?.length || 0) + (this.pdoc.additional_file?.length || 0) >= system.get('limit.problem_files_max')) {
throw new ForbiddenError('File limit exceeded.');
}
if (!this.request.files.file) throw new ValidationError('file');
const size = Math.sum((this.pdoc.data || []).map((i) => i.size), (this.pdoc.additional_file || []).map((i) => i.size));
if (size >= system.get('limit.problem_files_max_size')) {
throw new ForbiddenError('File size limit exceeded.');
}
if (!filename) filename = this.request.files.file.name || String.random(16);
if (filename.includes('/') || filename.includes('..')) throw new ValidationError('filename', null, 'Bad filename');
if (!this.user.hasPriv(PRIV.PRIV_EDIT_SYSTEM)) {
if ((this.pdoc.data?.length || 0) + (this.pdoc.additional_file?.length || 0)
>= system.get('limit.problem_files_max')) {
throw new ForbiddenError('File limit exceeded.');
}
const size = Math.sum((this.pdoc.data || []).map((i) => i.size), (this.pdoc.additional_file || []).map((i) => i.size));
if (size >= system.get('limit.problem_files_max_size')) {
throw new ForbiddenError('File size limit exceeded.');
}
}
if (!this.user.own(this.pdoc, PERM.PERM_EDIT_PROBLEM_SELF)) this.checkPerm(PERM.PERM_EDIT_PROBLEM);
if (filename.endsWith('.zip')) {
const zip = new AdmZip(this.request.files.file.path);
const entries = zip.getEntries();
for (const entry of entries) {
// TODO check file size
if (!entry.name) continue;
if (type === 'testdata') {
// eslint-disable-next-line no-await-in-loop
+2
View File
@@ -160,12 +160,14 @@ export interface ProblemConfigFile {
judge_extra_files?: string[];
detail?: boolean;
outputs?: [string, number][];
redirect?: string;
cases?: TestCaseConfig[];
subtasks?: SubtaskConfig[];
langs?: string[];
}
export interface ProblemConfig {
redirect?: [string, string];
count: number;
memoryMax: number;
memoryMin: number;
@@ -36,6 +36,7 @@ export async function parseConfig(config: string | ProblemConfigFile = {}) {
result.timeMax = result.timeMin = 1000;
}
if (cfg.langs) result.langs = cfg.langs;
if (cfg.redirect) result.redirect = cfg.redirect.split('/', 2) as any;
if (cfg.filename && result.type === 'default') {
result.type = 'fileio';
result.subType = cfg.filename;
+3 -3
View File
@@ -88,9 +88,9 @@ export interface Types {
}
export const Types: Types = {
Content: [(v) => v.toString(), isContent],
Name: [(v) => v.toString(), isName],
Title: [(v) => v.toString(), isTitle],
Content: [(v) => v.toString().trim(), isContent],
Name: [(v) => v.toString().trim(), isName],
Title: [(v) => v.toString().trim(), isTitle],
String: [(v) => v.toString(), null],
Int: [(v) => parseInt(v, 10), (v) => isSafeInteger(parseInt(v, 10))],
UnsignedInt: [(v) => parseInt(v, 10), (v) => parseInt(v, 10) >= 0],