Commit 1467bbd5 authored by Dmitry Timoshkov's avatar Dmitry Timoshkov Committed by Alexandre Julliard

Relax a bit PE consistency checks.

Return BINARY_DOS type if extended header was not recognized.
parent 155710ce
...@@ -635,15 +635,14 @@ enum binary_type MODULE_GetBinaryType( HANDLE hfile ) ...@@ -635,15 +635,14 @@ enum binary_type MODULE_GetBinaryType( HANDLE hfile )
*/ */
if (!memcmp( magic, "PE\0\0", 4 )) if (!memcmp( magic, "PE\0\0", 4 ))
{ {
IMAGE_NT_HEADERS nt; IMAGE_FILE_HEADER FileHeader;
if (SetFilePointer( hfile, header.mz.e_lfanew, NULL, SEEK_SET ) != -1 && if (ReadFile( hfile, &FileHeader, sizeof(FileHeader), &len, NULL ) && len == sizeof(FileHeader))
ReadFile( hfile, &nt, sizeof(nt), &len, NULL ) && len == sizeof(nt))
{ {
if (nt.FileHeader.Characteristics & IMAGE_FILE_DLL) return BINARY_PE_DLL; if (FileHeader.Characteristics & IMAGE_FILE_DLL) return BINARY_PE_DLL;
return BINARY_PE_EXE; return BINARY_PE_EXE;
} }
return BINARY_UNKNOWN; return BINARY_DOS;
} }
if (!memcmp( magic, "NE", 2 )) if (!memcmp( magic, "NE", 2 ))
...@@ -666,7 +665,7 @@ enum binary_type MODULE_GetBinaryType( HANDLE hfile ) ...@@ -666,7 +665,7 @@ enum binary_type MODULE_GetBinaryType( HANDLE hfile )
} }
} }
/* Couldn't read header, so abort. */ /* Couldn't read header, so abort. */
return BINARY_UNKNOWN; return BINARY_DOS;
} }
/* Unknown extended header, but this file is nonetheless DOS-executable. */ /* Unknown extended header, but this file is nonetheless DOS-executable. */
......
...@@ -211,8 +211,13 @@ static int get_image_params( struct mapping *mapping ) ...@@ -211,8 +211,13 @@ static int get_image_params( struct mapping *mapping )
if (read( fd, &dos, sizeof(dos) ) != sizeof(dos)) goto error; if (read( fd, &dos, sizeof(dos) ) != sizeof(dos)) goto error;
if (dos.e_magic != IMAGE_DOS_SIGNATURE) goto error; if (dos.e_magic != IMAGE_DOS_SIGNATURE) goto error;
if (lseek( fd, dos.e_lfanew, SEEK_SET ) == -1) goto error; if (lseek( fd, dos.e_lfanew, SEEK_SET ) == -1) goto error;
if (read( fd, &nt, sizeof(nt) ) != sizeof(nt)) goto error;
if (read( fd, &nt.Signature, sizeof(nt.Signature) ) != sizeof(nt.Signature)) goto error;
if (nt.Signature != IMAGE_NT_SIGNATURE) goto error; if (nt.Signature != IMAGE_NT_SIGNATURE) goto error;
if (read( fd, &nt.FileHeader, sizeof(nt.FileHeader) ) != sizeof(nt.FileHeader)) goto error;
/* zero out Optional header in the case it's not present or partial */
memset(&nt.OptionalHeader, 0, sizeof(nt.OptionalHeader));
if (read( fd, &nt.OptionalHeader, nt.FileHeader.SizeOfOptionalHeader) != nt.FileHeader.SizeOfOptionalHeader) goto error;
/* load the section headers */ /* load the section headers */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment