From 7b022c46d0b6dcd57fb3f885a20719253e34115c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marvin=20Ha=CC=88user?= <8659494+mhaeuser@users.noreply.github.com> Date: Sun, 2 Apr 2023 15:26:55 +0200 Subject: [PATCH] MdePkg/BasePeCoffLib2: Only validate ExeHdrOffset when non-zero --- MdePkg/Library/BasePeCoffLib2/PeCoffInit.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/MdePkg/Library/BasePeCoffLib2/PeCoffInit.c b/MdePkg/Library/BasePeCoffLib2/PeCoffInit.c index cffb1410db..0209c0d847 100644 --- a/MdePkg/Library/BasePeCoffLib2/PeCoffInit.c +++ b/MdePkg/Library/BasePeCoffLib2/PeCoffInit.c @@ -840,6 +840,13 @@ PeCoffInitializeContext ( } Context->ExeHdrOffset = DosHdr->e_lfanew; + // + // Verify the Execution Header offset is sufficiently aligned. + // + if (!PcdGetBool (PcdImageLoaderAllowMisalignedOffset) + && !IS_ALIGNED (Context->ExeHdrOffset, ALIGNOF (EFI_IMAGE_NT_HEADERS_COMMON_HDR))) { + return RETURN_UNSUPPORTED; + } } else if (!PcdGetBool (PcdImageLoaderProhibitTe)) { // // Assume the Image starts with the Executable Header, determine whether it @@ -865,13 +872,6 @@ PeCoffInitializeContext ( if (FileSize - Context->ExeHdrOffset < sizeof (EFI_IMAGE_NT_HEADERS_COMMON_HDR) + sizeof (UINT16)) { return RETURN_UNSUPPORTED; } - // - // Verify the Execution Header offset is sufficiently aligned. - // - if (!PcdGetBool (PcdImageLoaderAllowMisalignedOffset) - && !IS_ALIGNED (Context->ExeHdrOffset, ALIGNOF (EFI_IMAGE_NT_HEADERS_COMMON_HDR))) { - return RETURN_UNSUPPORTED; - } STATIC_ASSERT ( ALIGNOF (UINT32) <= ALIGNOF (EFI_IMAGE_NT_HEADERS_COMMON_HDR),