From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.24; helo=mga09.intel.com; envelope-from=shenglei.zhang@intel.com; receiver=edk2-devel@lists.01.org Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 09F11211E0953 for ; Wed, 20 Mar 2019 23:32:05 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 20 Mar 2019 23:32:04 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,251,1549958400"; d="scan'208";a="136114598" Received: from shenglei-mobl.ccr.corp.intel.com ([10.239.198.148]) by fmsmga007.fm.intel.com with ESMTP; 20 Mar 2019 23:32:03 -0700 From: shenglei To: edk2-devel@lists.01.org Cc: Shenglei Zhang , Michael D Kinney , Liming Gao Date: Thu, 21 Mar 2019 14:31:49 +0800 Message-Id: <20190321063149.13260-4-shenglei.zhang@intel.com> X-Mailer: git-send-email 2.18.0.windows.1 In-Reply-To: <20190321063149.13260-1-shenglei.zhang@intel.com> References: <20190321063149.13260-1-shenglei.zhang@intel.com> Subject: [PATCH v2 3/3] MdePkg/BaseUefiDecompressLib: Improve performance of boundary validation X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 21 Mar 2019 06:32:05 -0000 From: Shenglei Zhang The boundary validation checking in MakeTable() performs on every loop iteration. This could be improved by checking just once before the loop. https://bugzilla.tianocore.org/show_bug.cgi?id=1329 Cc: Michael D Kinney Cc: Liming Gao Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Shenglei Zhang --- .../Library/BaseUefiDecompressLib/BaseUefiDecompressLib.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/MdePkg/Library/BaseUefiDecompressLib/BaseUefiDecompressLib.c b/MdePkg/Library/BaseUefiDecompressLib/BaseUefiDecompressLib.c index c1e8c5581a..3d5b7a737a 100644 --- a/MdePkg/Library/BaseUefiDecompressLib/BaseUefiDecompressLib.c +++ b/MdePkg/Library/BaseUefiDecompressLib/BaseUefiDecompressLib.c @@ -222,10 +222,11 @@ MakeTable ( if (Len <= TableBits) { + if (Start[Len] >= NextCode || NextCode > MaxTableLength){ + return (UINT16) BAD_TABLE; + } + for (Index = Start[Len]; Index < NextCode; Index++) { - if (Index >= MaxTableLength) { - return (UINT16) BAD_TABLE; - } Table[Index] = Char; } -- 2.18.0.windows.1