Selaa lähdekoodia

MinPlatformPkg: Add missing bounds checks to CompressLib

Current code only as bounds checks in ASSERT macros.
They are also needed in release mode where ASSERT is not used.

Signed-off-by: Nate DeSimone <nathaniel.l.desimone@intel.com>
Cc: Chasel Chiu <chasel.chiu@intel.com>
Cc: Nate DeSimone <nathaniel.l.desimone@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Eric Dong <eric.dong@intel.com>
Reviewed-by: Chasel Chiu <chasel.chiu@intel.com>
Nate DeSimone 3 vuotta sitten
vanhempi
commit
b9f61c0789

+ 8 - 2
Platform/Intel/MinPlatformPkg/Library/CompressLib/CompressLib.c

@@ -1002,7 +1002,10 @@ CountTFreq (
         mTFreq[2]++;
       }
     } else {
-      ASSERT((LoopVar3+2)<(2 * NT - 1));
+      ASSERT ((LoopVar3 + 2) < (2 * NT - 1));
+      if ((LoopVar3 + 2) >= (2 * NT - 1)) {
+        return;
+      }
       mTFreq[LoopVar3 + 2]++;
     }
   }
@@ -1101,7 +1104,10 @@ WriteCLen (
         PutBits (CBIT, Count - 20);
       }
     } else {
-      ASSERT((LoopVar3+2)<NPT);
+      ASSERT ((LoopVar3 + 2) < NPT);
+      if ((LoopVar3 + 2) >= NPT) {
+        return;
+      }
       PutBits (mPTLen[LoopVar3 + 2], mPTCode[LoopVar3 + 2]);
     }
   }