From 8bf8213a7dbf426be79337f68cdc9fa7b5191871 Mon Sep 17 00:00:00 2001 From: goyuken Date: Tue, 21 Jan 2014 22:29:51 +0000 Subject: [PATCH] NES: truncate if a iNES file's supposed VROM size is longer than the leftover length of the iNES file. seems to fix some hacks\translations --- BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.cs index e8c1dec85f..e94c299acb 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.cs @@ -749,7 +749,9 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES { board.VROM = new byte[choice.chr_size * 1024]; int vrom_offset = iNesHeaderInfo.prg_size * 1024; - Array.Copy(file, 16 + vrom_offset, board.VROM, 0, board.VROM.Length); + // if file isn't long enough for VROM, truncate + + Array.Copy(file, 16 + vrom_offset, board.VROM, 0, Math.Min(board.VROM.Length, file.Length - 16 - vrom_offset)); } } else