(Xp3Opener): additional sanity check when searching archives inside EXE files.

This commit is contained in:
morkt 2016-03-05 17:18:28 +04:00
parent bb55fe7eed
commit d7ef400a31

View File

@ -315,14 +315,21 @@ NextEntry:
try { try {
for (byte* ptr = page_begin; ptr != page_end; ++ptr) for (byte* ptr = page_begin; ptr != page_end; ++ptr)
{ {
// TODO: search every byte only when inside resource section,
// otherwise stick to paragraph boundary.
int i = 0; int i = 0;
while (ptr[i] == s_xp3_header[i]) while (ptr[i] == s_xp3_header[i])
{ {
if (++i == s_xp3_header.Length) if (++i == s_xp3_header.Length)
{
// check whether index offset is non-zero
if (0 == *(uint*)(ptr+i))
break;
return offset + (ptr - page_begin); return offset + (ptr - page_begin);
} }
} }
} }
}
finally { finally {
view.SafeMemoryMappedViewHandle.ReleasePointer(); view.SafeMemoryMappedViewHandle.ReleasePointer();
} }