aboutsummaryrefslogtreecommitdiff
path: root/engines/kyra/resource.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'engines/kyra/resource.cpp')
-rw-r--r--engines/kyra/resource.cpp14
1 files changed, 9 insertions, 5 deletions
diff --git a/engines/kyra/resource.cpp b/engines/kyra/resource.cpp
index 73ff591792..04cfcf879a 100644
--- a/engines/kyra/resource.cpp
+++ b/engines/kyra/resource.cpp
@@ -795,7 +795,7 @@ Common::SeekableReadStream *ResLoaderTlk::loadFileFromArchive(const Common::Stri
class FileExpanderSource {
public:
- FileExpanderSource(const uint8 *data) : _dataPtr(data), _bitsLeft(8), _key(0), _index(0) {}
+ FileExpanderSource(const uint8 *data, int dataSize) : _dataPtr(data), _endofBuffer(data + dataSize), _bitsLeft(8), _key(0), _index(0) {}
~FileExpanderSource() {}
void advSrcRefresh();
@@ -811,6 +811,7 @@ public:
private:
const uint8 *_dataPtr;
+ const uint8 *_endofBuffer;
uint16 _key;
int8 _bitsLeft;
uint8 _index;
@@ -819,7 +820,8 @@ private:
void FileExpanderSource::advSrcBitsBy1() {
_key >>= 1;
if (!--_bitsLeft) {
- _key = ((*_dataPtr++) << 8 ) | (_key & 0xff);
+ if (_dataPtr < _endofBuffer)
+ _key = ((*_dataPtr++) << 8 ) | (_key & 0xff);
_bitsLeft = 8;
}
}
@@ -831,7 +833,8 @@ void FileExpanderSource::advSrcBitsByIndex(uint8 newIndex) {
_key >>= (_index + _bitsLeft);
_index = -_bitsLeft;
_bitsLeft = 8 - _index;
- _key = (*_dataPtr++ << 8) | (_key & 0xff);
+ if (_dataPtr < _endofBuffer)
+ _key = (*_dataPtr++ << 8) | (_key & 0xff);
}
_key >>= _index;
}
@@ -880,7 +883,8 @@ uint16 FileExpanderSource::keyMaskedAlign(uint16 val) {
void FileExpanderSource::advSrcRefresh() {
_key = READ_LE_UINT16(_dataPtr);
- _dataPtr += 2;
+ if (_dataPtr < _endofBuffer - 1)
+ _dataPtr += 2;
_bitsLeft = 8;
}
@@ -937,7 +941,7 @@ bool FileExpander::process(uint8 *dst, const uint8 *src, uint32 outsize, uint32
bool needrefresh = true;
bool postprocess = false;
- _src = new FileExpanderSource(src);
+ _src = new FileExpanderSource(src, compressedSize);
while (d < dst + outsize) {