diff --git a/engines/parallaction/iff.cpp b/engines/parallaction/iff.cpp index c48b12f888d..8f8ba0a838d 100644 --- a/engines/parallaction/iff.cpp +++ b/engines/parallaction/iff.cpp @@ -39,6 +39,22 @@ void IFFParser::setInputStream(Common::SeekableReadStream *stream) { _stream = stream; _startOffset = 0; _endOffset = _stream->size(); + + _formType = 0; + _formSize = (uint32)-1; + + if (_stream->size() < 12) { + // this file is too small to be a valid IFF container + return; + } + + if (_stream->readUint32BE() != ID_FORM) { + // no FORM header was found + return; + } + + _formSize = _stream->readUint32BE(); + _formType = _stream->readUint32BE(); } void IFFParser::destroy() { @@ -46,18 +62,12 @@ void IFFParser::destroy() { _startOffset = _endOffset = 0; } -uint32 IFFParser::getFORMBlockSize() { - uint32 oldOffset = _stream->pos(); +uint32 IFFParser::getFORMSize() const { + return _formSize; +} - uint32 data = _stream->readUint32BE(); - - if (data != ID_FORM) { - _stream->seek(oldOffset); - return (uint32)-1; - } - - data = _stream->readUint32BE(); - return data; +Common::IFF_ID IFFParser::getFORMType() const { + return _formType; } uint32 IFFParser::moveToIFFBlock(Common::IFF_ID chunkName) { @@ -117,6 +127,10 @@ ILBMDecoder::ILBMDecoder(Common::SeekableReadStream *in, bool disposeStream) : _ assert(in); _parser.setInputStream(in); + if (_parser.getFORMType() != ID_ILBM) { + return; + } + _hasHeader = _parser.loadIFFBlock(ID_BMHD, &_header, sizeof(_header)); if (!_hasHeader) { return; diff --git a/engines/parallaction/iff.h b/engines/parallaction/iff.h index 6edd28a17f1..43f78bf001c 100644 --- a/engines/parallaction/iff.h +++ b/engines/parallaction/iff.h @@ -46,7 +46,9 @@ public: operator bool() const { return (_startOffset != _endOffset) && _stream; } - uint32 getFORMBlockSize(); + uint32 getFORMSize() const; + Common::IFF_ID getFORMType() const; + uint32 getIFFBlockSize(Common::IFF_ID chunk); bool loadIFFBlock(Common::IFF_ID chunk, void *loadTo, uint32 ptrSize); Common::SeekableReadStream *getIFFBlockStream(Common::IFF_ID chunkName); @@ -57,6 +59,9 @@ private: Common::SeekableReadStream *_stream; uint32 _startOffset; uint32 _endOffset; + + uint32 _formSize; + Common::IFF_ID _formType; };