From 167eb95b3a3d62781ddb8ab4754e0b5d0d8ae6d0 Mon Sep 17 00:00:00 2001 From: Michael Pavone Date: Tue, 4 Aug 2015 21:43:20 -0700 Subject: Prevent crashes if game tries to access the ROM area outside of the size of the actual ROM --- romdb.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'romdb.c') diff --git a/romdb.c b/romdb.c index 8ccd76b..53a8fde 100644 --- a/romdb.c +++ b/romdb.c @@ -493,7 +493,7 @@ void add_memmap_header(rom_info *info, uint8_t *rom, uint32_t size, memmap_chunk memcpy(info->map+2, base_map, sizeof(memmap_chunk) * base_chunks); if (ram_start >= rom_end) { - info->map[0].end = rom_end > 0x400000 ? rom_end : 0x400000; + info->map[0].end = rom_end < 0x400000 ? nearest_pow2(rom_end) - 1 : 0xFFFFFF; //TODO: ROM mirroring info->map[0].mask = 0xFFFFFF; info->map[0].flags = MMAP_READ; @@ -542,8 +542,8 @@ void add_memmap_header(rom_info *info, uint8_t *rom, uint32_t size, memmap_chunk memset(info->map, 0, sizeof(memmap_chunk)); memcpy(info->map+1, base_map, sizeof(memmap_chunk) * base_chunks); - info->map[0].end =rom_end > 0x400000 ? rom_end : 0x400000; - info->map[0].mask = 0xFFFFFF; + info->map[0].end = rom_end > 0x400000 ? rom_end : 0x400000; + info->map[0].mask = rom_end < 0x400000 ? nearest_pow2(rom_end) - 1 : 0xFFFFFF; info->map[0].flags = MMAP_READ; info->map[0].buffer = rom; info->save_type = SAVE_NONE; -- cgit v1.2.3