From fa9396afd06d618095afd21c56e23015157dea17 Mon Sep 17 00:00:00 2001 From: undefined Date: Wed, 3 Mar 2021 13:13:00 +0800 Subject: [PATCH] =?UTF-8?q?fps:=20=E5=A2=9E=E5=8A=A0=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=A4=A7=E5=B0=8F=E9=99=90=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/fps-importer/handler.ts | 8 ++++++-- packages/fps-importer/package.json | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/fps-importer/handler.ts b/packages/fps-importer/handler.ts index c783a12fe..a5bc52bb9 100644 --- a/packages/fps-importer/handler.ts +++ b/packages/fps-importer/handler.ts @@ -10,7 +10,7 @@ import { buildContent } from 'hydrooj/dist/lib/content'; import { ProblemAdd } from 'hydrooj/dist/lib/ui'; import * as solution from 'hydrooj/dist/model/solution'; import { PERM } from 'hydrooj/dist/model/builtin'; -import { ValidationError } from 'hydrooj/dist/error'; +import { BadRequestError, ValidationError } from 'hydrooj/dist/error'; class FpsProblemImportHandler extends Handler { async get() { @@ -63,6 +63,8 @@ class FpsProblemImportHandler extends Handler { if (!this.request.files.file) throw new ValidationError('file'); const tasks = []; try { + const file = await fs.stat(this.request.files.file.path); + if (file.size > 64 * 1024 * 1024) throw new BadRequestError('File too large'); const content = fs.readFile(this.request.files.file.path).toString(); const result = await xml2js.parseStringPromise(content); tasks.push(result); @@ -70,7 +72,9 @@ class FpsProblemImportHandler extends Handler { const zip = new AdmZip(this.request.files.file.path); for (const entry of zip.getEntries()) { try { - const content = entry.getData().toString(); + const buf = entry.getData(); + if (buf.byteLength > 64 * 1024 * 1024) throw new BadRequestError('File too large'); + const content = buf.toString(); const result = await xml2js.parseStringPromise(content); tasks.push(result); } catch { } // eslint-disable-line no-empty diff --git a/packages/fps-importer/package.json b/packages/fps-importer/package.json index 4e4b9c174..f3b99ed30 100644 --- a/packages/fps-importer/package.json +++ b/packages/fps-importer/package.json @@ -1,6 +1,6 @@ { "name": "@hydrooj/fps-importer", - "version": "1.1.6", + "version": "1.1.7", "description": "Import FPS problems", "main": "package.json", "repository": "https://github.com/hydro-dev/Hydro.git",