Browse Source

Correctly load corrupted otmm file, should fix #606

Konrad Kuśnierz 6 years ago
parent
commit
11990815a6
1 changed files with 10 additions and 3 deletions
  1. 10
    3
      src/client/minimap.cpp

+ 10
- 3
src/client/minimap.cpp View File

@@ -333,6 +333,7 @@ bool Minimap::loadOtmm(const std::string& fileName)
333 333
 
334 334
         uint blockSize = MMBLOCK_SIZE * MMBLOCK_SIZE * sizeof(MinimapTile);
335 335
         std::vector<uchar> compressBuffer(compressBound(blockSize));
336
+        std::vector<uchar> decompressBuffer(blockSize);
336 337
 
337 338
         while(true) {
338 339
             Position pos;
@@ -344,13 +345,19 @@ bool Minimap::loadOtmm(const std::string& fileName)
344 345
             if(!pos.isValid())
345 346
                 break;
346 347
 
348
+            // corrupted file
349
+            if(pos.z >= Otc::MAX_Z+1)
350
+                break;
351
+
347 352
             MinimapBlock& block = getBlock(pos);
348 353
             ulong len = fin->getU16();
349 354
             ulong destLen = blockSize;
350 355
             fin->read(compressBuffer.data(), len);
351
-            int ret = uncompress((uchar*)&block.getTiles(), &destLen, compressBuffer.data(), len);
352
-            assert(ret == Z_OK);
353
-            assert(destLen == blockSize);
356
+            int ret = uncompress(decompressBuffer.data(), &destLen, compressBuffer.data(), len);
357
+            if(ret != Z_OK || destLen != blockSize)
358
+                break;
359
+
360
+            memcpy((uchar*)&block.getTiles(), decompressBuffer.data(), blockSize);
354 361
             block.mustUpdate();
355 362
             block.justSaw();
356 363
         }

Loading…
Cancel
Save