diff --git a/MdePkg/Library/BasePeCoffLib/BasePeCoff.c b/MdePkg/Library/BasePeCoffLib/BasePeCoff.c index 4b71176a0c..86ff2e769b 100644 --- a/MdePkg/Library/BasePeCoffLib/BasePeCoff.c +++ b/MdePkg/Library/BasePeCoffLib/BasePeCoff.c @@ -585,6 +585,7 @@ PeCoffLoaderGetImageInfo ( UINTN Size; UINTN ReadSize; UINTN Index; + UINTN NextIndex; UINTN DebugDirectoryEntryRva; UINTN DebugDirectoryEntryFileOffset; UINTN SectionHeaderOffset; @@ -755,6 +756,20 @@ PeCoffLoaderGetImageInfo ( ImageContext->ImageSize += DebugEntry.SizeOfData; } + // + // Implementations of GenFw before commit 60e85a39fe49071 will + // concatenate the debug directory entry and the codeview entry, + // and erroneously put the combined size into the debug directory's + // size field. If this is the case, no other relevant directory + // entries can exist, and we can terminate here. + // + NextIndex = Index + sizeof (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY); + if ((NextIndex < DebugDirectoryEntry->Size) && + (DebugEntry.FileOffset == (DebugDirectoryEntryFileOffset + NextIndex))) + { + break; + } + continue; }