On Fri, 29 Nov 2024, Pali Rohár wrote:
PE format allows to have variable length of Data Directories in PE Optional
Header. The exact number of Data Directories is stored in NumberOfRvaAndSizes
field. Size of the optional header depends on the number of Data Directories.
Constants IMAGE_SIZEOF_NT_OPTIONAL32_HEADER and
IMAGE_SIZEOF_NT_OPTIONAL64_HEADER
are for PE images with all 16 Data Directories. And so cannot be used for
checking validity of SizeOfOptionalHeader.
Older PE linkers were generating PE binaries with less number of Data
Directories than 16 if trailing entries were empty. And gendef cannot
recognize such PE binaries.
Relax check for PE SizeOfOptionalHeader field. Allow any number of Data
Directories in PE Optional Header, including zero.
---
mingw-w64-tools/gendef/src/gendef.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/mingw-w64-tools/gendef/src/gendef.c
b/mingw-w64-tools/gendef/src/gendef.c
index 7440d60f35df..ae9603fe1a3a 100644
--- a/mingw-w64-tools/gendef/src/gendef.c
+++ b/mingw-w64-tools/gendef/src/gendef.c
@@ -313,19 +313,19 @@ load_pep (void)
gPEDta = NULL;
return 0;
}
- if (gPEDta->FileHeader.SizeOfOptionalHeader ==
IMAGE_SIZEOF_NT_OPTIONAL32_HEADER
+ if (gPEDta->FileHeader.SizeOfOptionalHeader >=
IMAGE_SIZEOF_NT_OPTIONAL32_HEADER-sizeof(gPEDta->OptionalHeader.DataDirectory)
This looks ok, but the expression
IMAGE_SIZEOF_NT_OPTIONAL32_HEADER -
sizeof(gPEDta->OptionalHeader.DataDirectory)
feels somewhat clumsy; is there any more concise way of expressing this,
like some sort of offsetof() or so?
The functionality of the patch itself seems fine though.
(I know there are a few other older patchsets I haven't commented on yet,
but I wanted to reply to this one sooner, as it seemed quicker to review.)
// Martin
_______________________________________________
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public