August 08, 2023
https://issues.dlang.org/show_bug.cgi?id=24079

          Issue ID: 24079
           Summary: core.sys.windows.winnt.IMAGE_FIRST_SECTION returns bad
                    pointer
           Product: D
           Version: D2
          Hardware: All
                OS: Windows
            Status: NEW
          Severity: normal
          Priority: P1
         Component: druntime
          Assignee: nobody@puremagic.com
          Reporter: n8sh.secondary@hotmail.com

IMAGE_FIRST_SECTION adds an integer representing a number of bytes to a pointer of type IMAGE_OPTIONAL_HEADER* resulting in a change 240 times (IMAGE_OPTIONAL_HEADER64*) or 224 times (IMAGE_OPTIONAL_HEADER32*) as large as intended.

https://learn.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-image_file_header "SizeOfOptionalHeader: The size of the optional header, in bytes."

core.sys.windows.winnt.d:
---
PIMAGE_SECTION_HEADER IMAGE_FIRST_SECTION(PIMAGE_NT_HEADERS h) {
    return cast(PIMAGE_SECTION_HEADER)
        (&h.OptionalHeader + h.FileHeader.SizeOfOptionalHeader);
}
---

--