diff --git a/engines/director/archive.cpp b/engines/director/archive.cpp index 10a6b35f69a..8d4d4c3692f 100644 --- a/engines/director/archive.cpp +++ b/engines/director/archive.cpp @@ -640,15 +640,19 @@ bool RIFXArchive::readAfterburnerMap(Common::SeekableSubReadStreamEndian &stream } uint32 abmpLength = readVarInt(stream); uint32 abmpCompressionType = readVarInt(stream); - uint32 abmpUncompLength = readVarInt(stream); - debug(3, "ABMP: length: %d compressionType: %d uncompressedLength: %d", + unsigned long abmpUncompLength = readVarInt(stream); + unsigned long abmpActualUncompLength = abmpUncompLength; + debug(3, "ABMP: length: %d compressionType: %d uncompressedLength: %lu", abmpLength, abmpCompressionType, abmpUncompLength); - Common::SeekableReadStreamEndian *abmpStream = readZlibData(stream, abmpLength, abmpUncompLength, _isBigEndian); + Common::SeekableReadStreamEndian *abmpStream = readZlibData(stream, abmpLength, &abmpActualUncompLength, _isBigEndian); if (!abmpStream) { warning("RIFXArchive::readAfterburnerMap(): Could not uncompress ABMP"); return false; } + if (abmpUncompLength != abmpActualUncompLength) { + warning("ABMP: Expected uncompressed length %lu but got length %lu", abmpUncompLength, abmpActualUncompLength); + } if (ConfMan.getBool("dump_scripts")) { Common::DumpFile out; diff --git a/engines/director/util.cpp b/engines/director/util.cpp index 57c0537b7fb..18856fc88ca 100644 --- a/engines/director/util.cpp +++ b/engines/director/util.cpp @@ -671,20 +671,20 @@ uint32 readVarInt(Common::SeekableReadStream &stream) { return val; } -Common::SeekableReadStreamEndian *readZlibData(Common::SeekableReadStream &stream, unsigned long len, unsigned long outLen, bool bigEndian) { +Common::SeekableReadStreamEndian *readZlibData(Common::SeekableReadStream &stream, unsigned long len, unsigned long *outLen, bool bigEndian) { #ifdef USE_ZLIB byte *in = (byte *)malloc(len); - byte *out = (byte *)malloc(outLen); + byte *out = (byte *)malloc(*outLen); stream.read(in, len); - if (!Common::uncompress(out, &outLen, in, len)) { + if (!Common::uncompress(out, outLen, in, len)) { free(in); free(out); return nullptr; } free(in); - return new Common::MemoryReadStreamEndian(out, outLen, bigEndian); + return new Common::MemoryReadStreamEndian(out, *outLen, bigEndian); # else return nullptr; # endif diff --git a/engines/director/util.h b/engines/director/util.h index 7be84db5b3c..009291e33d9 100644 --- a/engines/director/util.h +++ b/engines/director/util.h @@ -78,7 +78,7 @@ private: uint32 readVarInt(Common::SeekableReadStream &stream); -Common::SeekableReadStreamEndian *readZlibData(Common::SeekableReadStream &stream, unsigned long len, unsigned long outLen, bool bigEndian); +Common::SeekableReadStreamEndian *readZlibData(Common::SeekableReadStream &stream, unsigned long len, unsigned long *outLen, bool bigEndian); } // End of namespace Director