From e4c2754493ca3f85d0e782201d6be3fc8cf5a353 Mon Sep 17 00:00:00 2001 From: C-3PO Date: Wed, 4 Jul 2018 19:36:25 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9A=A0=20Add=20error=20message=20if=20file?= =?UTF-8?q?=20too=20large?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/cdn/getUrlContents.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/cdn/getUrlContents.ts b/src/cdn/getUrlContents.ts index 6715394..c12b478 100644 --- a/src/cdn/getUrlContents.ts +++ b/src/cdn/getUrlContents.ts @@ -1,5 +1,7 @@ import * as http from 'http'; +const MAX_MEMORY_SIZE = 100 * 1024 * 1024; + export default function getUrlContents({ host, path }: {host: string, path: string}): Promise { return new Promise((resolve, reject) => { const request = http.request({ @@ -11,6 +13,11 @@ export default function getUrlContents({ host, path }: {host: string, path: stri return reject(`Expected status code 200 but received ${response.statusCode}`); } const headerLength = Number(response.headers['content-length']); + if (headerLength > MAX_MEMORY_SIZE) { + reject('File size too large to be handled in memory.'); + request.abort(); + return; + } const chunkList: Buffer[] = []; let totalLength = 0;