From nobody Fri May 17 00:04:37 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+49455+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+49455+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1571997356; cv=none; d=zoho.com; s=zohoarc; b=lCsjsNv0c76lOyUD9q7WS9GU/fppgL82vl0zvf4zxqJgFBcrxdEHAlaZ+XYUgOlebqq4TK9JzkA83jCMWNGWEdCFXUnsJNDGxJ7B1WbCVliQm8Po4bqEmO7j4qiUOfUXxxEEOY9n6G4kzJPK7lhFbN1057jA32sq16W72Y+jjj8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571997356; h=Cc:Date:From:List-Id:List-Unsubscribe:Message-ID:Reply-To:Sender:Subject:To; bh=mlNKF7OfBGb92AKNrFsMEXisDu5DGcUA0/yRaK1Pt6k=; b=XDEPQOSbDbGBaAQNFYbUsaA+rpljUwYFcA8DMt31lz8YY6Il6qCwVpAx+mjHZlJz49ji1QnyKGBIWau6Lg/LhzTbY9kKTt+NHwIXLLUG/swIIQCYsA6Ennxqp/3KPs5eFSqdbW+XAxYaMLzdKpNrwtrb7jLjxnp/vZyL/CYE7Qk= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+49455+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 157199735646849.31886238554398; Fri, 25 Oct 2019 02:55:56 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id aaaaYY1788612xaaaaaaaaaa; Fri, 25 Oct 2019 02:55:55 -0700 X-Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by mx.groups.io with SMTP id smtpd.web11.2693.1571997354819026354 for ; Fri, 25 Oct 2019 02:55:54 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 25 Oct 2019 02:55:54 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.68,228,1569308400"; d="scan'208";a="192491902" X-Received: from cchiu4-mobl1.gar.corp.intel.com ([10.5.215.138]) by orsmga008.jf.intel.com with ESMTP; 25 Oct 2019 02:55:52 -0700 From: "Chiu, Chasel" To: devel@edk2.groups.io Cc: Maurice Ma , Nate DeSimone , Star Zeng Subject: [edk2-devel] [PATCH] IntelFsp2Pkg/SplitFspBin.py: Command crashed when FV almost full. Date: Fri, 25 Oct 2019 17:55:46 +0800 Message-Id: <20191025095546.1832-1-chasel.chiu@intel.com> Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,chasel.chiu@intel.com X-Gm-Message-State: aaaaaaaaaaaaaaaaaaaaaaaax1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1571997355; bh=GDkLIYDFr3s5DfyubGGX40jX2Xkx2oamjkkpuO+Mi9E=; h=Cc:Date:From:Reply-To:Subject:To; b=D1CZJaiQWXS6k0KE9+ggealpeE4rjmuC4rBsenGnHeQLX4iQSVYOgpJ8frzyfQ7ETb1 Lrzrojk5YejMcgr0OY17kMgJpuLCRlnYV30NRabGhOD/v0spIy/+aOjKctXp4ULL/ITRc l6B/hSTHiRkPpCj3nUoyxr1Jniij40F8B1Q= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Nate DeSimone --- IntelFsp2Pkg/Tools/SplitFspBin.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/IntelFsp2Pkg/Tools/SplitFspBin.py b/IntelFsp2Pkg/Tools/SplitFs= pBin.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.Ffs= Data, offset) sec =3D Section (offset, self.FfsData[offset:offset + int(= sechdr.Size)]) self.SecList.append(sec) @@ -453,7 +453,7 @@ class FirmwareVolume: 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, offse= t) 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, o= ffset) if b'_FVH' !=3D fvh.Signature: raise Exception("ERROR: Invalid FV header !") @@ -838,7 +838,7 @@ def RebaseFspBin (FspBinary, FspComponent, FspBase, Out= putDir, OutputFile): =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"which= ") =20 parser_rebase =3D subparsers.add_parser('rebase', help=3D'rebase a F= SP 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 --=20 2.13.3.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#49455): https://edk2.groups.io/g/devel/message/49455 Mute This Topic: https://groups.io/mt/37475458/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-