From e5ee53afa6efc280cad0257c95f95d45d4850f25 Mon Sep 17 00:00:00 2001 From: sorgelig Date: Mon, 20 Apr 2020 05:57:18 +0800 Subject: [PATCH] arcade: fix the buffer overflow. --- support/arcade/romutils.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/support/arcade/romutils.cpp b/support/arcade/romutils.cpp index 8d61667..82d7b11 100644 --- a/support/arcade/romutils.cpp +++ b/support/arcade/romutils.cpp @@ -191,10 +191,10 @@ static int rom_data(const uint8_t *buf, int chunk, int map, struct MD5Context *m return 1; } -extern uint8_t loadbuf[]; static int rom_file(const char *name, uint32_t crc32, int start, int len, int map, struct MD5Context *md5context) { fileTYPE f = {}; + static uint8_t buf[8192]; if (!FileOpenZip(&f, name, crc32)) return 0; if (start) FileSeek(&f, start, SEEK_SET); unsigned long bytes2send = f.size - f.offset; @@ -202,10 +202,10 @@ static int rom_file(const char *name, uint32_t crc32, int start, int len, int ma while (bytes2send) { - uint32_t chunk = (bytes2send > LOADBUF_SZ) ? LOADBUF_SZ : bytes2send; + uint16_t chunk = (bytes2send > sizeof(buf)) ? sizeof(buf) : bytes2send; - FileReadAdv(&f, loadbuf, chunk); - if (!rom_data(loadbuf, chunk, map, md5context)) + FileReadAdv(&f, buf, chunk); + if (!rom_data(buf, chunk, map, md5context)) { FileClose(&f); return 0;