(DAT/YaneSDK): added sanity checks.

This commit is contained in:
morkt 2017-12-02 05:10:41 +04:00
parent 2d89134535
commit 32b256b013

View File

@ -56,6 +56,7 @@ namespace GameRes.Formats.YaneSDK
using (var index = new BinaryReader (dec)) using (var index = new BinaryReader (dec))
{ {
index.BaseStream.Position = 2; index.BaseStream.Position = 2;
int data_offset = 2 + 0x2C * count;
var name_buf = new byte[0x22]; var name_buf = new byte[0x22];
var dir = new List<Entry> (count); var dir = new List<Entry> (count);
for (int i = 0; i < count; ++i) for (int i = 0; i < count; ++i)
@ -63,11 +64,13 @@ namespace GameRes.Formats.YaneSDK
if (0x22 != index.Read (name_buf, 0, 0x22)) if (0x22 != index.Read (name_buf, 0, 0x22))
return null; return null;
var name = Binary.GetCString (name_buf, 0); var name = Binary.GetCString (name_buf, 0);
if (string.IsNullOrWhiteSpace (name))
return null;
var entry = FormatCatalog.Instance.Create<YaneEntry> (name); var entry = FormatCatalog.Instance.Create<YaneEntry> (name);
entry.EncryptedSize = index.ReadUInt16(); entry.EncryptedSize = index.ReadUInt16();
entry.Size = index.ReadUInt32(); entry.Size = index.ReadUInt32();
entry.Offset = index.ReadUInt32(); entry.Offset = index.ReadUInt32();
if (!entry.CheckPlacement (file.MaxOffset)) if (!entry.CheckPlacement (file.MaxOffset) || entry.Offset <= data_offset)
return null; return null;
dir.Add (entry); dir.Add (entry);
} }