aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorMartin Kiewitz2015-06-16 00:15:15 +0200
committerMartin Kiewitz2015-06-16 00:15:15 +0200
commit662732acd7e0277b893c1f6f6fd5e0af5db0b9d4 (patch)
treef2aed84ba7f50d2d2239b33fc16f83ff1781ca7c /engines
parent668b8d827e21044d5dea9c1351a10a5d76506ada (diff)
downloadscummvm-rg350-662732acd7e0277b893c1f6f6fd5e0af5db0b9d4.tar.gz
scummvm-rg350-662732acd7e0277b893c1f6f6fd5e0af5db0b9d4.tar.bz2
scummvm-rg350-662732acd7e0277b893c1f6f6fd5e0af5db0b9d4.zip
SHERLOCK: 3DO: animation loader: verify data
Diffstat (limited to 'engines')
-rw-r--r--engines/sherlock/image_file.cpp28
1 files changed, 19 insertions, 9 deletions
diff --git a/engines/sherlock/image_file.cpp b/engines/sherlock/image_file.cpp
index 5a315637b3..78284e416d 100644
--- a/engines/sherlock/image_file.cpp
+++ b/engines/sherlock/image_file.cpp
@@ -342,13 +342,17 @@ inline uint16 ImageFile3DO::convertPixel(uint16 pixel3DO) {
}
void ImageFile3DO::loadAnimationFile(Common::SeekableReadStream &stream) {
- int streamSize = stream.size();
- uint32 compressedSize = 0;
+ uint32 streamLeft = stream.size() - stream.pos();
+ uint32 celDataSize = 0;
- while (stream.pos() < streamSize) {
+ while (streamLeft > 0) {
ImageFrame frame;
- compressedSize = stream.readUint16BE();
+ // We expect a basic header of 8 bytes
+ if (streamLeft < 8)
+ error("load3DOAnimationFile: expected animation header, not enough bytes");
+
+ celDataSize = stream.readUint16BE();
frame._width = stream.readUint16BE() + 1; // 2 bytes BE width
frame._height = stream.readByte() + 1; // 1 byte BE height
@@ -357,21 +361,27 @@ void ImageFile3DO::loadAnimationFile(Common::SeekableReadStream &stream) {
frame._rleEncoded = true; // always compressed
if (frame._width & 0x8000) {
frame._width &= 0x7FFF;
- compressedSize += 0x10000;
+ celDataSize += 0x10000;
}
frame._offset.x = stream.readUint16BE();
frame._offset.y = stream.readByte();
frame._size = 0;
+ // Got header
+ streamLeft -= 8;
- //warning("getting frame %d from offset %d", this->size(), stream.pos());
+ // cel data follows
+ if (streamLeft < celDataSize)
+ error("load3DOAnimationFile: expected cel data, not enough bytes");
+ //
// Load data for frame and decompress it
- byte *data = new byte[compressedSize];
- stream.read(data, compressedSize);
+ byte *data = new byte[celDataSize];
+ stream.read(data, celDataSize);
+ streamLeft -= celDataSize;
// always 16 bits per pixel (RGB555)
- decompress3DOCelFrame(frame, data, compressedSize, 16, NULL);
+ decompress3DOCelFrame(frame, data, celDataSize, 16, NULL);
delete[] data;