]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
Revert "lzma: Make sure we don't dereference past array"
authorLidong Chen <lidong.chen@oracle.com>
Mon, 23 Jun 2025 17:42:32 +0000 (17:42 +0000)
committerDaniel Kiper <daniel.kiper@oracle.com>
Thu, 26 Jun 2025 16:05:08 +0000 (18:05 +0200)
Commit 40e261b89b71 (lib/LzmaEnc: Validate "len" before subtracting)
ensures that the variable len is at least 2. As a result, GetLenToPosState(len)
never returns a value greater than or equal to kNumLenToPosStates,
making the changes introduced in the commit 16c0dbf4bc6a (lzma: Make
sure we don't dereference past array) unreachable and no longer necessary.

This reverts commit 16c0dbf4bc6a (lzma: Make sure we don't dereference past array).

Fixes: CID 481982
Signed-off-by: Lidong Chen <lidong.chen@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
grub-core/lib/LzmaEnc.c

index e97cd15a087c21a6e1c1ea78d016cac21d5e5b5b..0fb2cf1d41d1b67113e3f5a8c6ca76b8f79a62ef 100644 (file)
@@ -1877,7 +1877,7 @@ static SRes LzmaEnc_CodeOneBlock(CLzmaEnc *p, Bool useLimits, UInt32 maxPackSize
       }
       else
       {
-        UInt32 posSlot, lenToPosState;
+        UInt32 posSlot;
         RangeEnc_EncodeBit(&p->rc, &p->isRep[p->state], 0);
         p->state = kMatchNextStates[p->state];
         if (len < LZMA_MATCH_LEN_MIN)
@@ -1888,13 +1888,7 @@ static SRes LzmaEnc_CodeOneBlock(CLzmaEnc *p, Bool useLimits, UInt32 maxPackSize
         LenEnc_Encode2(&p->lenEnc, &p->rc, len - LZMA_MATCH_LEN_MIN, posState, !p->fastMode, p->ProbPrices);
         pos -= LZMA_NUM_REPS;
         GetPosSlot(pos, posSlot);
-        lenToPosState = GetLenToPosState(len);
-        if (lenToPosState >= kNumLenToPosStates)
-        {
-          p->result = SZ_ERROR_DATA;
-          return CheckErrors(p);
-        }
-        RcTree_Encode(&p->rc, p->posSlotEncoder[lenToPosState], kNumPosSlotBits, posSlot);
+        RcTree_Encode(&p->rc, p->posSlotEncoder[GetLenToPosState(len)], kNumPosSlotBits, posSlot);
 
         if (posSlot >= kStartPosModelIndex)
         {