From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by mx.groups.io with SMTP id smtpd.web09.101.1572046001169019891 for ; Fri, 25 Oct 2019 16:26:41 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 192.55.52.151, mailfrom: nathaniel.l.desimone@intel.com) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 25 Oct 2019 16:26:40 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.68,230,1569308400"; d="scan'208";a="197565047" Received: from orsmsx109.amr.corp.intel.com ([10.22.240.7]) by fmsmga008.fm.intel.com with ESMTP; 25 Oct 2019 16:26:40 -0700 Received: from orsmsx113.amr.corp.intel.com ([169.254.9.28]) by ORSMSX109.amr.corp.intel.com ([169.254.11.239]) with mapi id 14.03.0439.000; Fri, 25 Oct 2019 16:26:40 -0700 From: "Nate DeSimone" To: "devel@edk2.groups.io" , "Chiu, Chasel" CC: "Ma, Maurice" , "Zeng, Star" Subject: Re: [edk2-devel] [PATCH] IntelFsp2Pkg/SplitFspBin.py: Command crashed when FV almost full. Thread-Topic: [edk2-devel] [PATCH] IntelFsp2Pkg/SplitFspBin.py: Command crashed when FV almost full. Thread-Index: AQHVixpmZceLz6bcg0+C5LDdF8n7eKdsAP9w Date: Fri, 25 Oct 2019 23:26:40 +0000 Message-ID: <02A34F284D1DA44BB705E61F7180EF0AB5B7AA63@ORSMSX113.amr.corp.intel.com> References: <20191025095546.1832-1-chasel.chiu@intel.com> In-Reply-To: <20191025095546.1832-1-chasel.chiu@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-product: dlpe-windows dlp-version: 11.2.0.6 dlp-reaction: no-action x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiYTZkMGJhMGQtMWI5OS00Y2ZiLWFiYTItMmJhMTA5YjBjOTM2IiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjEwLjE4MDQuNDkiLCJUcnVzdGVkTGFiZWxIYXNoIjoiS3JIdVwvSm1NbFl1QjM4VlVONkRKbysrOFMxYUJ6UzQwcWlLKzk2M3EwKzl2VkJKdUpIYVJyMGppc1VKb1g3V3MifQ== x-ctpclassification: CTP_NT x-originating-ip: [10.22.254.139] MIME-Version: 1.0 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Good Catch! Reviewed-by: Nate DeSimone -----Original Message----- From: devel@edk2.groups.io On Behalf Of Chiu, Chase= l Sent: Friday, October 25, 2019 2:56 AM To: devel@edk2.groups.io Cc: Ma, Maurice ; Desimone, Nathaniel L ; Zeng, Star Subject: [edk2-devel] [PATCH] IntelFsp2Pkg/SplitFspBin.py: Command crashed= when FV almost full. REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2310 When target FV 99% used and only few bytes space left, SplitFspBin.py may = crash with below error: File "SplitFspBin.py", line 457, in ParseFv ffshdr =3D EFI_FFS_FILE_HEADER.from_buffer (self.FvData, offset) ValueError: Buffer size too small (40960 instead of at least 40968 bytes) It was because the offset used by FFS_HEADER parser out of bounds. It should stop parsing when offset equal or larger than (buffer size + FFS= _HEADER size). This patch also fixed another crash issue when running script with Python = 3.x and no input parameter given: File "SplitFspBin.py", line 868, in main if args.which in ['rebase', 'split', 'genhdr', 'info']: AttributeError: 'Namespace' object has no attribute 'which' Test: 1. Ran script with both py2 and py3 with no input and no crash observed. 2. Compare the script result before and after the patch are identical. Cc: Maurice Ma Cc: Nate DeSimone Cc: Star Zeng Signed-off-by: Chasel Chiu --- IntelFsp2Pkg/Tools/SplitFspBin.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/IntelFsp2Pkg/Tools/SplitFspBin.py b/IntelFsp2Pkg/Tools/SplitF= spBin.py index b326241fa9..39a7ea7460 100644 --- a/IntelFsp2Pkg/Tools/SplitFspBin.py +++ b/IntelFsp2Pkg/Tools/SplitFspBin.py @@ -428,7 +428,7 @@ class FirmwareFile: ffssize =3D len(self.FfsData) offset =3D sizeof(self.FfsHdr) if self.FfsHdr.Name !=3D '\xff' * 16: - while offset < ffssize: + while offset < (ffssize - sizeof (EFI_COMMON_SECTION_HEADER))= : sechdr =3D EFI_COMMON_SECTION_HEADER.from_buffer (self.Ff= sData, offset) sec =3D Section (offset, self.FfsData[offset:offset + int= (sechdr.Size)]) self.SecList.append(sec) @@ -453,7 +453,7 @@ class Firmwa= reVolume: else: offset =3D self.FvHdr.HeaderLength offset =3D AlignPtr(offset) - while offset < fvsize: + while offset < (fvsize - sizeof (EFI_FFS_FILE_HEADER)): ffshdr =3D EFI_FFS_FILE_HEADER.from_buffer (self.FvData, offs= et) if (ffshdr.Name =3D=3D '\xff' * 16) and (int(ffshdr.Size) =3D= = =3D 0xFFFFFF): offset =3D fvsize @@ -515,7 +515,7 @@ class FirmwareDevice: offset =3D 0 fdsize =3D len(self.FdData) self.FvList =3D [] - while offset < fdsize: + while offset < (fdsize - sizeof (EFI_FIRMWARE_VOLUME_HEADER)): fvh =3D EFI_FIRMWARE_VOLUME_HEADER.from_buffer (self.FdData, = offset) if b'_FVH' !=3D fvh.Signature: raise Exception("ERROR: Invalid FV header !") @@ -838,7 += 838,7 @@ def RebaseFspBin (FspBinary, FspComponent, FspBase, OutputDir, Out= putFile): =20 def main (): parser =3D argparse.ArgumentParser() - subparsers =3D parser.add_subparsers(title=3D'commands') + subparsers =3D parser.add_subparsers(title=3D'commands', dest=3D"whic= h") =20 parser_rebase =3D subparsers.add_parser('rebase', help=3D'rebase a = FSP into a new base address') parser_rebase.set_defaults(which=3D'rebase') @@ -880,7 +880,7 @@ def main (): elif args.which =3D=3D 'info': ShowFspInfo (args.FspBinary) else: - pass + parser.print_help() =20 return 0 =20 -- 2.13.3.windows.1