]> git.proxmox.com Git - mirror_edk2.git/commitdiff
BaseTools GenFw: Fix the issue to update the wrong size as SectionSize
authorLiming Gao <liming.gao@intel.com>
Thu, 17 Oct 2019 06:55:47 +0000 (14:55 +0800)
committerLiming Gao <liming.gao@intel.com>
Thu, 24 Oct 2019 01:41:31 +0000 (09:41 +0800)
BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=1603
CLANG9 generated PE image exposes below two issues.
1. SectionSize is used to copy PE section data. It should be smaller than
section raw size.
2. The real data is required to be copied. So, copy the min size of
VirtualSize and SizeOfRawData.

Signed-off-by: Liming Gao <liming.gao@intel.com>
Cc: Bob Feng <bob.c.feng@intel.com>
Reviewed-by: Philippe Mathieu-Daude <philmd@redhat.com>
BaseTools/Source/C/GenFw/GenFw.c

index c99782b78eca89ccffeb94347f56b2cfb517667c..8cab70ba4d5f649057a068e842a0b810ec76e0e1 100644 (file)
@@ -653,7 +653,11 @@ PeCoffConvertImageToXip (
     //\r
     // Make the size of raw data in section header alignment.\r
     //\r
-    SectionHeader->SizeOfRawData = (SectionHeader->Misc.VirtualSize + PeHdr->Pe32.OptionalHeader.FileAlignment - 1) & (~(PeHdr->Pe32.OptionalHeader.FileAlignment - 1));\r
+    SectionSize = (SectionHeader->Misc.VirtualSize + PeHdr->Pe32.OptionalHeader.FileAlignment - 1) & (~(PeHdr->Pe32.OptionalHeader.FileAlignment - 1));\r
+    if (SectionSize < SectionHeader->SizeOfRawData) {\r
+      SectionHeader->SizeOfRawData = SectionSize;\r
+    }\r
+\r
     SectionHeader->PointerToRawData = SectionHeader->VirtualAddress;\r
   }\r
 \r
@@ -999,7 +1003,7 @@ Returns:
     CopyMem (\r
       FileBuffer + SectionHeader->PointerToRawData,\r
       (VOID*) (UINTN) (ImageContext.ImageAddress + SectionHeader->VirtualAddress),\r
-      SectionHeader->SizeOfRawData\r
+      SectionHeader->SizeOfRawData < SectionHeader->Misc.VirtualSize ? SectionHeader->SizeOfRawData : SectionHeader->Misc.VirtualSize\r
       );\r
   }\r
 \r