When copying the relocated sections into the FFS file, we need to
take care that we don't overrun the end of the file. Since, unlike
the virtual size, the PE/COFF raw section size must be a multiple of
the file alignment, which means its size may exceed the virtual size.
So use the minimum of the two.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ard Biesheuvel <ard.biesheu...@linaro.org>
---
 BaseTools/Source/C/GenFv/GenFvInternalLib.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/BaseTools/Source/C/GenFv/GenFvInternalLib.c 
b/BaseTools/Source/C/GenFv/GenFvInternalLib.c
index 6d2d5d1f8c67..b0135bf0155a 100644
--- a/BaseTools/Source/C/GenFv/GenFvInternalLib.c
+++ b/BaseTools/Source/C/GenFv/GenFvInternalLib.c
@@ -3329,7 +3329,7 @@ Returns:
       CopyMem (
         (UINT8 *) CurrentPe32Section.Pe32Section + CurSecHdrSize + 
SectionHeader->PointerToRawData, 
         (VOID*) (UINTN) (ImageContext.ImageAddress + 
SectionHeader->VirtualAddress), 
-        SectionHeader->SizeOfRawData
+        MIN(SectionHeader->SizeOfRawData, SectionHeader->Misc.VirtualSize)
         );
     }
 
-- 
1.9.1

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel

Reply via email to