offsetof(IMAGE_OPTIONAL_HEADER, DataDirectory) is the minimal size of
variable length OptionalHeader (IMAGE_OPTIONAL_HEADER) structure.
if (nt_header->Signature != IMAGE_NT_SIGNATURE)
return NULL;
+ if (nt_header->FileHeader.SizeOfOptionalHeader < offsetof(IMAGE_OPTIONAL_HEADER, DataDirectory))
+ return NULL;
+
if (nt_header->OptionalHeader.Magic != IMAGE_NT_OPTIONAL_HDR_MAGIC)
return NULL;
return FALSE;
#endif
+ /* IMAGE_OPTIONAL_HEADER is alias for the structure used on the target compiler architecture. */
+ if (nt_headers->FileHeader.SizeOfOptionalHeader < offsetof(IMAGE_OPTIONAL_HEADER, DataDirectory))
+ return FALSE;
+
/* IMAGE_NT_OPTIONAL_HDR_MAGIC is alias for the header magic used on the target compiler architecture. */
if (nt_headers->OptionalHeader.Magic != IMAGE_NT_OPTIONAL_HDR_MAGIC)
return FALSE;