From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by mx.groups.io with SMTP id smtpd.web12.5510.1571755502136308385 for ; Tue, 22 Oct 2019 07:45:02 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 192.55.52.115, mailfrom: liming.gao@intel.com) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 22 Oct 2019 07:44:57 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.67,327,1566889200"; d="scan'208";a="197139483" Received: from lgao4-mobl1.ccr.corp.intel.com ([10.255.31.203]) by fmsmga007.fm.intel.com with ESMTP; 22 Oct 2019 07:44:57 -0700 From: "Liming Gao" To: devel@edk2.groups.io Cc: Bob Feng Subject: [Patch 03/11] BaseTools GenFw: Fix the issue to update the wrong size as SectionSize Date: Tue, 22 Oct 2019 22:43:57 +0800 Message-Id: <20191022144406.6996-4-liming.gao@intel.com> X-Mailer: git-send-email 2.16.2.windows.1 In-Reply-To: <20191022144406.6996-1-liming.gao@intel.com> References: <20191022144406.6996-1-liming.gao@intel.com> 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 Cc: Bob Feng Reviewed-by: Philippe Mathieu-Daude --- BaseTools/Source/C/GenFw/GenFw.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/BaseTools/Source/C/GenFw/GenFw.c b/BaseTools/Source/C/GenFw/GenFw.c index c99782b78e..8cab70ba4d 100644 --- a/BaseTools/Source/C/GenFw/GenFw.c +++ b/BaseTools/Source/C/GenFw/GenFw.c @@ -653,7 +653,11 @@ PeCoffConvertImageToXip ( // // Make the size of raw data in section header alignment. // - SectionHeader->SizeOfRawData = (SectionHeader->Misc.VirtualSize + PeHdr->Pe32.OptionalHeader.FileAlignment - 1) & (~(PeHdr->Pe32.OptionalHeader.FileAlignment - 1)); + SectionSize = (SectionHeader->Misc.VirtualSize + PeHdr->Pe32.OptionalHeader.FileAlignment - 1) & (~(PeHdr->Pe32.OptionalHeader.FileAlignment - 1)); + if (SectionSize < SectionHeader->SizeOfRawData) { + SectionHeader->SizeOfRawData = SectionSize; + } + SectionHeader->PointerToRawData = SectionHeader->VirtualAddress; } @@ -999,7 +1003,7 @@ Returns: CopyMem ( FileBuffer + SectionHeader->PointerToRawData, (VOID*) (UINTN) (ImageContext.ImageAddress + SectionHeader->VirtualAddress), - SectionHeader->SizeOfRawData + SectionHeader->SizeOfRawData < SectionHeader->Misc.VirtualSize ? SectionHeader->SizeOfRawData : SectionHeader->Misc.VirtualSize ); } -- 2.13.0.windows.1