Added simple IFF type verification to the parser.

svn-id: r39609
This commit is contained in:
Nicola Mettifogo 2009-03-22 15:30:42 +00:00
parent 631e0aaed5
commit 2b8140d765
2 changed files with 31 additions and 12 deletions

View File

@ -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;

View File

@ -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;
};