From 55756c88aec9d3269d8544746907838ba921e90b Mon Sep 17 00:00:00 2001 From: Shenglei Zhang Date: Mon, 25 Feb 2019 13:53:37 +0800 Subject: BaseTools/C/Common: Improve performance of boundary validation 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: Bob Feng Cc: Liming Gao Cc: Yonghong Zhu Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Shenglei Zhang Reviewed-by: Liming Gao --- BaseTools/Source/C/Common/Decompress.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'BaseTools') diff --git a/BaseTools/Source/C/Common/Decompress.c b/BaseTools/Source/C/Common/Decompress.c index 0e9ba0a982..e9ac1d58b3 100644 --- a/BaseTools/Source/C/Common/Decompress.c +++ b/BaseTools/Source/C/Common/Decompress.c @@ -254,10 +254,11 @@ Returns: 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; } -- cgit v1.2.3