opening a .sav file should not crash

This commit is contained in:
Benjamin Popp 2019-01-25 20:59:07 -06:00
parent b2335968dc
commit 048cceb0d7
2 changed files with 16 additions and 0 deletions

View File

@ -163,6 +163,7 @@ namespace HavenSoft.Gen3Hex.Core.Models {
if (RawData[i] % 4 != 0) continue;
var source = i;
var destination = ReadPointer(i);
if (destination >= RawData.Length) continue;
if (!pointersForDestination.ContainsKey(destination)) pointersForDestination[destination] = new List<int>();
pointersForDestination[destination].Add(source);
destinationForSource.Add(source, destination);

View File

@ -336,5 +336,20 @@ namespace HavenSoft.Gen3Hex.Tests {
Assert.Equal(13, model.GetNextRun(0x08).Length);
Assert.Equal("\"Hello World!\"", ((PCS)viewPort[0x0C, 0].Format).FullString);
}
[Fact]
public void PointersPastEndOfDataDoNotCountAsPointers() {
var buffer = Enumerable.Repeat((byte)0xFF, 0x200).ToArray();
buffer[4] = 0x20;
buffer[5] = 0x20;
buffer[6] = 0x20;
buffer[7] = 0x08;
// it should realize that the data starting at 4 isn't a pointer
// because 202020 is after the end of the data
var model = new PointerAndStringModel(buffer);
Assert.Equal(int.MaxValue, model.GetNextRun(0).Start);
}
}
}