Fixed undefined behaviour in rfx decoder

This commit is contained in:
akallabeth 2020-05-15 15:40:12 +02:00
parent ee160fc414
commit a1dd25e219
1 changed files with 12 additions and 3 deletions

View File

@ -282,7 +282,10 @@ int rfx_rlgr_decode(RLGR_MODE mode, const BYTE* pSrcData, UINT32 SrcSize, INT16*
break;
bs->mask = ((1 << kr) - 1);
code = (UINT16)((bs->accumulator >> (32 - kr)) & bs->mask);
if (kr > 0)
code = (UINT16)((bs->accumulator >> (32 - kr)) & bs->mask);
else
code = 0;
BitStream_Shift(bs, kr);
/* add (vk << kr) to code */
@ -390,7 +393,10 @@ int rfx_rlgr_decode(RLGR_MODE mode, const BYTE* pSrcData, UINT32 SrcSize, INT16*
break;
bs->mask = ((1 << kr) - 1);
code = (UINT16)((bs->accumulator >> (32 - kr)) & bs->mask);
if (kr > 0)
code = (UINT16)((bs->accumulator >> (32 - kr)) & bs->mask);
else
code = 0;
BitStream_Shift(bs, kr);
/* add (vk << kr) to code */
@ -477,7 +483,10 @@ int rfx_rlgr_decode(RLGR_MODE mode, const BYTE* pSrcData, UINT32 SrcSize, INT16*
break;
bs->mask = ((1 << nIdx) - 1);
val1 = ((bs->accumulator >> (32 - nIdx)) & bs->mask);
if (nIdx > 0)
val1 = ((bs->accumulator >> (32 - nIdx)) & bs->mask);
else
val1 = 0;
BitStream_Shift(bs, nIdx);
val2 = code - val1;