From e93ee87643a30df3bffede2f4cdadfc7be88f0bd Mon Sep 17 00:00:00 2001 From: Evgenii Shatokhin Date: Mon, 20 Oct 2025 10:54:59 +0300 Subject: BaseTools: FMMT: Fix incorrect size calculation in ModifyTest() There is another issue in FvHander.py similar to the one fixed by a60334ad59eb ("BaseTools: Fix FMMT FvHandler Padding operation issue"). For a guided section (ParTree.Data.Type == 0x02), the length of ParTree.Data.OriData is used to obtain the original size of the data even after ParTree.Data.OriData has changed, which is incorrect. This caused the following issue I observed. I built OVMF image for Aarch64 and then tried to add a couple FFS modules to it with 'FMMT -a [...]'. The resulting image turned out to be invalid: the total size of the image was less than the size of the firmware volume within it. UEFITool failed to load such firmware image and complained: "parseRawArea: one of objects inside overlaps the end of data". This patch fixes the issue. Signed-off-by: Evgenii Shatokhin --- BaseTools/Source/Python/FMMT/core/FvHandler.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'BaseTools/Source/Python') diff --git a/BaseTools/Source/Python/FMMT/core/FvHandler.py b/BaseTools/Source/Python/FMMT/core/FvHandler.py index 12d52c1ac3..6ecbffa245 100644 --- a/BaseTools/Source/Python/FMMT/core/FvHandler.py +++ b/BaseTools/Source/Python/FMMT/core/FvHandler.py @@ -346,7 +346,8 @@ class FvHandler: raise Exception("Process Failed: GuidTool not found!") # Recompress current data, and recalculate the needed space CompressedData = guidtool.pack(ParTree.Data.Data) - Needed_Space = len(CompressedData) - len(ParTree.Data.OriData) + Original_Data_Size = len(ParTree.Data.OriData) + Needed_Space = len(CompressedData) - Original_Data_Size ParTree.Data.OriData = CompressedData New_Size = ParTree.Data.HeaderLength + len(CompressedData) ParTree.Data.Header.Size[0] = New_Size % (16**2) @@ -367,12 +368,12 @@ class FvHandler: if Needed_Space < 0: if ParTree.NextRel: self.Remain_New_Free_Space = ( - len(ParTree.Data.OriData) + Original_Pad_Size - + Original_Data_Size + Original_Pad_Size - len(CompressedData) - New_Pad_Size ) else: self.Remain_New_Free_Space = ( - len(ParTree.Data.OriData) - len(CompressedData) + Original_Data_Size - len(CompressedData) ) # If current section is not guided section elif Needed_Space: -- cgit v1.2.3