Correctly load corrupted otmm file, should fix #606

This commit is contained in:
Konrad Kuśnierz 2015-05-10 22:31:10 +02:00
parent ded8fef16b
commit 11990815a6
1 changed files with 10 additions and 3 deletions

View File

@ -333,6 +333,7 @@ bool Minimap::loadOtmm(const std::string& fileName)
uint blockSize = MMBLOCK_SIZE * MMBLOCK_SIZE * sizeof(MinimapTile); uint blockSize = MMBLOCK_SIZE * MMBLOCK_SIZE * sizeof(MinimapTile);
std::vector<uchar> compressBuffer(compressBound(blockSize)); std::vector<uchar> compressBuffer(compressBound(blockSize));
std::vector<uchar> decompressBuffer(blockSize);
while(true) { while(true) {
Position pos; Position pos;
@ -344,13 +345,19 @@ bool Minimap::loadOtmm(const std::string& fileName)
if(!pos.isValid()) if(!pos.isValid())
break; break;
// corrupted file
if(pos.z >= Otc::MAX_Z+1)
break;
MinimapBlock& block = getBlock(pos); MinimapBlock& block = getBlock(pos);
ulong len = fin->getU16(); ulong len = fin->getU16();
ulong destLen = blockSize; ulong destLen = blockSize;
fin->read(compressBuffer.data(), len); fin->read(compressBuffer.data(), len);
int ret = uncompress((uchar*)&block.getTiles(), &destLen, compressBuffer.data(), len); int ret = uncompress(decompressBuffer.data(), &destLen, compressBuffer.data(), len);
assert(ret == Z_OK); if(ret != Z_OK || destLen != blockSize)
assert(destLen == blockSize); break;
memcpy((uchar*)&block.getTiles(), decompressBuffer.data(), blockSize);
block.mustUpdate(); block.mustUpdate();
block.justSaw(); block.justSaw();
} }