From 02c9cb35f4e190891a4d59a2f335b817a9147334 Mon Sep 17 00:00:00 2001 From: Kari Salminen Date: Mon, 11 Aug 2008 20:09:03 +0000 Subject: Changed readBundleFile to unpack data in-place and added debugging messages to the function. svn-id: r33781 --- engines/cine/part.cpp | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'engines') diff --git a/engines/cine/part.cpp b/engines/cine/part.cpp index d605bdd623..d2fecfc554 100644 --- a/engines/cine/part.cpp +++ b/engines/cine/part.cpp @@ -221,17 +221,21 @@ void readFromPart(int16 idx, byte *dataPtr) { byte *readBundleFile(int16 foundFileIdx) { assert(foundFileIdx >= 0 && foundFileIdx < numElementInPart); + bool error = false; byte *dataPtr = (byte *)calloc(partBuffer[foundFileIdx].unpackedSize, 1); - if (partBuffer[foundFileIdx].unpackedSize != partBuffer[foundFileIdx].packedSize) { - byte *unpackBuffer = (byte *)malloc(partBuffer[foundFileIdx].packedSize); - readFromPart(foundFileIdx, unpackBuffer); + readFromPart(foundFileIdx, dataPtr); + if (partBuffer[foundFileIdx].unpackedSize > partBuffer[foundFileIdx].packedSize) { CineUnpacker cineUnpacker; - if (!cineUnpacker.unpack(unpackBuffer, partBuffer[foundFileIdx].packedSize, dataPtr, partBuffer[foundFileIdx].unpackedSize)) { - warning("Error unpacking '%s' from bundle file '%s'", partBuffer[foundFileIdx].partName, currentPartName); - } - free(unpackBuffer); - } else { - readFromPart(foundFileIdx, dataPtr); + error = !cineUnpacker.unpack(dataPtr, partBuffer[foundFileIdx].packedSize, dataPtr, partBuffer[foundFileIdx].unpackedSize); + } else if (partBuffer[foundFileIdx].unpackedSize < partBuffer[foundFileIdx].packedSize) { + // Unpacked size of a file should never be less than its packed size + error = true; + } else { // partBuffer[foundFileIdx].unpackedSize == partBuffer[foundFileIdx].packedSize + debugC(5, kCineDebugPart, "Loaded non-compressed file '%s' from bundle file '%s'", partBuffer[foundFileIdx].partName, currentPartName); + } + + if (error) { + warning("Error unpacking '%s' from bundle file '%s'", partBuffer[foundFileIdx].partName, currentPartName); } return dataPtr; -- cgit v1.2.3