]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdePkg/Library/BaseUefiDecompressLib/BaseUefiDecompressLib.c
Add check when use Index as Array [Index] to avoid out of Array bound.
[mirror_edk2.git] / MdePkg / Library / BaseUefiDecompressLib / BaseUefiDecompressLib.c
index f32eac49bf0329dc30ad84bce690f10af1e989d4..58f7791fe7c9504854e6cfaf31c657038dd37108 100644 (file)
@@ -153,14 +153,15 @@ MakeTable (
   UINT16  WordOfCount;\r
 \r
 \r
-  for (Index = 1; Index <= 16; Index++) {\r
+  for (Index = 0; Index <= 16; Index++) {\r
     Count[Index] = 0;\r
   }\r
 \r
   for (Index = 0; Index < NumOfChar; Index++) {\r
     Count[BitLen[Index]]++;\r
   }\r
-\r
+  \r
+  Start[0] = 0;\r
   Start[1] = 0;\r
 \r
   for (Index = 1; Index <= 16; Index++) {\r
@@ -175,7 +176,8 @@ MakeTable (
   }\r
 \r
   JuBits = (UINT16) (16 - TableBits);\r
-\r
+  \r
+  Weight[0] = 0;\r
   for (Index = 1; Index <= TableBits; Index++) {\r
     Start[Index] >>= JuBits;\r
     Weight[Index] = (UINT16) (1U << (TableBits - Index));\r
@@ -201,7 +203,7 @@ MakeTable (
   for (Char = 0; Char < NumOfChar; Char++) {\r
 \r
     Len = BitLen[Char];\r
-    if (Len == 0) {\r
+    if (Len == 0 || Len >= 17) {\r
       continue;\r
     }\r
 \r
@@ -221,7 +223,7 @@ MakeTable (
 \r
       while (Index != 0) {\r
         if (*Pointer == 0) {\r
-          Sd->mRight[Avail]                     = Sd->mLeft[Avail] = 0;\r
+          Sd->mRight[Avail] = Sd->mLeft[Avail] = 0;\r
           *Pointer = Avail++;\r
         }\r
 \r
@@ -347,7 +349,7 @@ ReadPTLen (
 \r
   Index = 0;\r
 \r
-  while (Index < Number) {\r
+  while (Index < Number && Index < NPT) {\r
 \r
     CharC = (UINT16) (Sd->mBitBuf >> (BITBUFSIZ - 3));\r
 \r
@@ -382,7 +384,7 @@ ReadPTLen (
     }\r
   }\r
 \r
-  while (Index < nn) {\r
+  while (Index < nn && Index < NPT) {\r
     Sd->mPTLen[Index++] = 0;\r
   }\r
   \r
@@ -428,7 +430,7 @@ ReadCLen (
   }\r
 \r
   Index = 0;\r
-  while (Index < Number) {\r
+  while (Index < Number && Index < NC) {\r
     CharC = Sd->mPTTable[Sd->mBitBuf >> (BITBUFSIZ - 8)];\r
     if (CharC >= NT) {\r
       Mask = 1U << (BITBUFSIZ - 1 - 8);\r