diff options
author | Nicola Mettifogo | 2009-03-22 15:30:42 +0000 |
---|---|---|
committer | Nicola Mettifogo | 2009-03-22 15:30:42 +0000 |
commit | 2b8140d7658705a6f032e6d7969de2505fda88ab (patch) | |
tree | f58656eb08a76fa89be289363d5c0950a957e26f | |
parent | 631e0aaed554fda923da020ffd0e6f9b18234ef9 (diff) | |
download | scummvm-rg350-2b8140d7658705a6f032e6d7969de2505fda88ab.tar.gz scummvm-rg350-2b8140d7658705a6f032e6d7969de2505fda88ab.tar.bz2 scummvm-rg350-2b8140d7658705a6f032e6d7969de2505fda88ab.zip |
Added simple IFF type verification to the parser.
svn-id: r39609
-rw-r--r-- | engines/parallaction/iff.cpp | 36 | ||||
-rw-r--r-- | engines/parallaction/iff.h | 7 |
2 files changed, 31 insertions, 12 deletions
diff --git a/engines/parallaction/iff.cpp b/engines/parallaction/iff.cpp index c48b12f888..8f8ba0a838 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 data = _stream->readUint32BE(); - - if (data != ID_FORM) { - _stream->seek(oldOffset); - return (uint32)-1; - } +uint32 IFFParser::getFORMSize() const { + return _formSize; +} - 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 6edd28a17f..43f78bf001 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; }; |