Commit 3dc21d38 authored by Alexandre Julliard's avatar Alexandre Julliard

ntdll: Map the PE header up to the specified size, and clear the rest of the page.

parent 64b2ca25
......@@ -360,12 +360,6 @@ START_TEST(loader)
start = (const char *)hlib + nt_header.OptionalHeader.SizeOfHeaders;
size = ALIGN_SIZE((ULONG_PTR)start, si.dwPageSize) - (ULONG_PTR)start;
/* remove next 'if' and todo_wine once Wine is fixed */
if (nt_header.OptionalHeader.SizeOfHeaders < nt_header.OptionalHeader.FileAlignment)
{
todo_wine ok(!memcmp(start, filler, size), "%d: header alignment is not cleared\n", i);
}
else
ok(!memcmp(start, filler, size), "%d: header alignment is not cleared\n", i);
}
......
......@@ -974,11 +974,12 @@ static NTSTATUS map_image( HANDLE hmapping, int fd, char *base, SIZE_T total_siz
status = STATUS_INVALID_IMAGE_FORMAT; /* generic error */
if (!st.st_size) goto error;
header_size = min( header_size, st.st_size );
if (map_file_into_view( view, fd, 0, header_size, 0, VPROT_COMMITTED | VPROT_READ,
if (map_file_into_view( view, fd, 0, header_size, 0, VPROT_COMMITTED | VPROT_READ | VPROT_WRITECOPY,
removable ) != STATUS_SUCCESS) goto error;
dos = (IMAGE_DOS_HEADER *)ptr;
nt = (IMAGE_NT_HEADERS *)(ptr + dos->e_lfanew);
header_end = ptr + ROUND_SIZE( 0, header_size );
memset( ptr + header_size, 0, header_end - (ptr + header_size) );
if ((char *)(nt + 1) > header_end) goto error;
sec = (IMAGE_SECTION_HEADER*)((char*)&nt->OptionalHeader+nt->FileHeader.SizeOfOptionalHeader);
if ((char *)(sec + nt->FileHeader.NumberOfSections) > header_end) goto error;
......@@ -1067,8 +1068,8 @@ static NTSTATUS map_image( HANDLE hmapping, int fd, char *base, SIZE_T total_siz
end = sec->VirtualAddress + ROUND_SIZE( sec->VirtualAddress, map_size );
if (sec->VirtualAddress > total_size || end > total_size || end < sec->VirtualAddress)
{
ERR_(module)( "Section %.8s too large (%x+%lx/%lx)\n",
sec->Name, sec->VirtualAddress, map_size, total_size );
WARN_(module)( "Section %.8s too large (%x+%lx/%lx)\n",
sec->Name, sec->VirtualAddress, map_size, total_size );
goto error;
}
......@@ -1166,6 +1167,8 @@ static NTSTATUS map_image( HANDLE hmapping, int fd, char *base, SIZE_T total_siz
/* set the image protections */
VIRTUAL_SetProt( view, ptr, ROUND_SIZE( 0, header_size ), VPROT_COMMITTED | VPROT_READ );
sec = (IMAGE_SECTION_HEADER*)((char *)&nt->OptionalHeader+nt->FileHeader.SizeOfOptionalHeader);
for (i = 0; i < nt->FileHeader.NumberOfSections; i++, sec++)
{
......
......@@ -243,11 +243,11 @@ static int get_image_params( struct mapping *mapping )
mapping->size = ROUND_SIZE( nt.OptionalHeader.SizeOfImage );
mapping->base = (void *)nt.OptionalHeader.ImageBase;
mapping->header_size = pos + size;
mapping->header_size = max( pos + size, nt.OptionalHeader.SizeOfHeaders );
mapping->protect = VPROT_IMAGE;
/* sanity check */
if (mapping->header_size > mapping->size) goto error;
if (pos + size > mapping->size) goto error;
free( sec );
release_object( fd );
......
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