(DrsOpener): additional entry offset sanity checks.

This commit is contained in:
morkt 2014-08-24 14:11:41 +04:00
parent db7df7f3d7
commit 1b85159ed2

View File

@ -43,7 +43,7 @@ namespace GameRes.Formats.DRS
public DrsOpener () public DrsOpener ()
{ {
Extensions = new string[0]; // DRS archives have no extensions Extensions = Enumerable.Empty<string>(); // DRS archives have no extensions
} }
public override ArcFile TryOpen (ArcView file) public override ArcFile TryOpen (ArcView file)
@ -60,7 +60,7 @@ namespace GameRes.Formats.DRS
int dir_offset = 2; int dir_offset = 2;
uint next_offset = file.View.ReadUInt32 (dir_offset+12); uint next_offset = file.View.ReadUInt32 (dir_offset+12);
if (next_offset > file.MaxOffset) if (next_offset > file.MaxOffset || next_offset < dir_size+2)
return null; return null;
var encoding = Encodings.cp932.WithFatalFallback(); var encoding = Encodings.cp932.WithFatalFallback();
byte[] name_raw = new byte[12]; byte[] name_raw = new byte[12];
@ -78,7 +78,7 @@ namespace GameRes.Formats.DRS
uint offset = next_offset; uint offset = next_offset;
dir_offset += 0x10; dir_offset += 0x10;
next_offset = file.View.ReadUInt32 (dir_offset+12); next_offset = file.View.ReadUInt32 (dir_offset+12);
if (next_offset > file.MaxOffset) if (next_offset > file.MaxOffset || next_offset < offset)
return null; return null;
string name = encoding.GetString (name_raw, 0, name_length).ToLowerInvariant(); string name = encoding.GetString (name_raw, 0, name_length).ToLowerInvariant();
var entry = FormatCatalog.Instance.CreateEntry (name); var entry = FormatCatalog.Instance.CreateEntry (name);