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;