From 85217f4c0d10b1ed13f47b2535dbc46de5669d2d Mon Sep 17 00:00:00 2001 From: Daryl Borth Date: Mon, 27 Aug 2018 09:34:42 -0600 Subject: [PATCH] prevent overrunning the file buffer (eg: loading a game cover image that's too big). increase buffer size to load larger IPS/UPS files. --- source/fileop.cpp | 12 ++++++++++++ source/fileop.h | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/source/fileop.cpp b/source/fileop.cpp index da04a88..d80c7bf 100644 --- a/source/fileop.cpp +++ b/source/fileop.cpp @@ -871,6 +871,18 @@ LoadFile (char * rbuffer, char *filepath, size_t length, bool silent) size_t LoadFile(char * filepath, bool silent) { + struct stat filestat; + + if(stat(filepath, &filestat) != 0) { + return 0; + } + + int size = filestat.st_size; + + if(size >= SAVEBUFFERSIZE) { + return 0; + } + return LoadFile((char *)savebuffer, filepath, 0, silent); } diff --git a/source/fileop.h b/source/fileop.h index 9ff49d3..569200f 100644 --- a/source/fileop.h +++ b/source/fileop.h @@ -18,7 +18,7 @@ #include #include -#define SAVEBUFFERSIZE (1024 * 512) +#define SAVEBUFFERSIZE (1024 * 1024 * 2) // leave room for IPS/UPS files and larger images void InitDeviceThread(); void ResumeDeviceThread();