Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/ClusterM/nes-containers.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexey 'Cluster' Avdyukhin <clusterrr@clusterrr.com>2020-12-17 12:46:43 +0300
committerAlexey 'Cluster' Avdyukhin <clusterrr@clusterrr.com>2020-12-17 12:46:43 +0300
commit46610e9effd868eb0d15234495c8f397c4871f79 (patch)
treeb24eff0619d405096a293de817967eee4fc32316
parent806278297c5939fcb645a06a6dbbb45eacff938b (diff)
PRG, CHR, trainer length check for bad ROMs
-rw-r--r--NesFile.cs9
1 files changed, 6 insertions, 3 deletions
diff --git a/NesFile.cs b/NesFile.cs
index 908c7c3..1b4d631 100644
--- a/NesFile.cs
+++ b/NesFile.cs
@@ -660,16 +660,19 @@ namespace com.clusterrr.Famicom.Containers
uint offset = (uint)header.Length;
if (trainer != null && trainer.Length > 0)
{
- Array.Copy(data, offset, trainer, 0, trainer.Length);
+ if (offset < data.Length)
+ Array.Copy(data, offset, trainer, 0, Math.Max(0, Math.Min(trainer.Length, data.Length - offset)));
offset += (uint)trainer.Length;
}
prg = new byte[prgSize];
- Array.Copy(data, offset, prg, 0, Math.Max(0, Math.Min(prgSize, data.Length - offset))); // Ignore end for some bad ROMs
+ if (offset < data.Length)
+ Array.Copy(data, offset, prg, 0, Math.Max(0, Math.Min(prgSize, data.Length - offset))); // Ignore end for some bad ROMs
offset += prgSize;
chr = new byte[chrSize];
- Array.Copy(data, offset, chr, 0, Math.Max(0, Math.Min(chrSize, data.Length - offset)));
+ if (offset < data.Length)
+ Array.Copy(data, offset, chr, 0, Math.Max(0, Math.Min(chrSize, data.Length - offset)));
offset += chrSize;
if (MiscellaneousROMsCount > 0)