From 9d1d707c01e6c59d2d6f9ae43cb58d8c29e8da33 Mon Sep 17 00:00:00 2001 From: negativeExponent Date: Fri, 28 Feb 2020 12:02:02 +0800 Subject: [PATCH] Limit ROM size to 32 MiB. Limit the utilLoad() function in src/Util.cpp to 32 MiB. This function loads a file from disk and returns a memory image of it. This is only used to load ROMs currently. --- src/Util.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Util.cpp b/src/Util.cpp index 1b470c67..5c15e7e0 100644 --- a/src/Util.cpp +++ b/src/Util.cpp @@ -60,6 +60,8 @@ static int(ZEXPORT *utilGzReadFunc)(gzFile, voidp, unsigned int) = NULL; static int(ZEXPORT *utilGzCloseFunc)(gzFile) = NULL; static z_off_t(ZEXPORT *utilGzSeekFunc)(gzFile, z_off_t, int) = NULL; +#define MAX_CART_SIZE 0x2000000 // 32MB + bool FileExists(const char *filename) { #ifdef _WIN32 @@ -586,6 +588,9 @@ uint8_t *utilLoad(const char *file, bool (*accept)(const char *), uint8_t *data, if (size == 0) size = fileSize; + if (size > MAX_CART_SIZE) + return NULL; + uint8_t *image = data; if (image == NULL) {