diff options
Diffstat (limited to 'engines/toon/tools.cpp')
-rw-r--r-- | engines/toon/tools.cpp | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/engines/toon/tools.cpp b/engines/toon/tools.cpp index e1478645db..bad796158a 100644 --- a/engines/toon/tools.cpp +++ b/engines/toon/tools.cpp @@ -200,7 +200,16 @@ uint16 RncDecoder::inputBits(uint8 amount) { newBitBuffl >>= newBitCount; newBitBuffl |= remBits; _srcPtr += 2; - newBitBuffh = READ_LE_UINT16(_srcPtr); + + // added some more check here to prevent reading in the buffer + // if there are no bytes anymore. + _inputByteLeft -= 2; + if (_inputByteLeft <= 0) + newBitBuffh = 0; + else if (_inputByteLeft == 1) + newBitBuffh = *_srcPtr; + else + newBitBuffh = READ_LE_UINT16(_srcPtr); amount -= newBitCount; newBitCount = 16 - amount; } @@ -283,7 +292,7 @@ int RncDecoder::getbit() { return temp; } -int32 RncDecoder::unpackM1(const void *input, void *output) { +int32 RncDecoder::unpackM1(const void *input, uint16 inputSize, void *output) { debugC(1, kDebugTools, "unpackM1(input, output)"); uint8 *outputLow, *outputHigh; @@ -295,6 +304,8 @@ int32 RncDecoder::unpackM1(const void *input, void *output) { uint16 crcUnpacked = 0; uint16 crcPacked = 0; + + _inputByteLeft = inputSize; _bitBuffl = 0; _bitBuffh = 0; _bitCount = 0; @@ -337,9 +348,12 @@ int32 RncDecoder::unpackM1(const void *input, void *output) { _srcPtr = (_dstPtr - packLen); } + _inputByteLeft -= HEADER_LEN; + _dstPtr = (uint8 *)output; _bitCount = 0; + _bitBuffl = READ_LE_UINT16(_srcPtr); inputBits(2); @@ -358,6 +372,7 @@ int32 RncDecoder::unpackM1(const void *input, void *output) { memcpy(_dstPtr, _srcPtr, inputLength); //memcpy is allowed here _dstPtr += inputLength; _srcPtr += inputLength; + _inputByteLeft -= inputLength; uint16 a = READ_LE_UINT16(_srcPtr); uint16 b = READ_LE_UINT16(_srcPtr + 2); |