diff options
author | Alexey 'Cluster' Avdyukhin <clusterrr@clusterrr.com> | 2020-12-17 12:46:43 +0300 |
---|---|---|
committer | Alexey 'Cluster' Avdyukhin <clusterrr@clusterrr.com> | 2020-12-17 12:46:43 +0300 |
commit | 46610e9effd868eb0d15234495c8f397c4871f79 (patch) | |
tree | b24eff0619d405096a293de817967eee4fc32316 | |
parent | 806278297c5939fcb645a06a6dbbb45eacff938b (diff) |
PRG, CHR, trainer length check for bad ROMs
-rw-r--r-- | NesFile.cs | 9 |
1 files changed, 6 insertions, 3 deletions
@@ -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)
|