diff options
author | Ladislav Zezula <ladislav.zezula@avast.com> | 2021-12-21 10:37:24 +0100 |
---|---|---|
committer | Ladislav Zezula <ladislav.zezula@avast.com> | 2021-12-21 10:37:24 +0100 |
commit | 7da097c51323f15752f252e8c5ed0bd1a349ec75 (patch) | |
tree | 1666ca90759e7343dfc6b188304723171f6ccc3f /src/SFileReadFile.cpp | |
parent | 76887d4bb0836b09a04c7ab578b6df5f1262812e (diff) |
Regression tests
Diffstat (limited to 'src/SFileReadFile.cpp')
-rw-r--r-- | src/SFileReadFile.cpp | 55 |
1 files changed, 31 insertions, 24 deletions
diff --git a/src/SFileReadFile.cpp b/src/SFileReadFile.cpp index 1703748..6ec04f3 100644 --- a/src/SFileReadFile.cpp +++ b/src/SFileReadFile.cpp @@ -159,34 +159,41 @@ static DWORD ReadMpqSectors(TMPQFile * hf, LPBYTE pbBuffer, DWORD dwByteOffset, // by comparing uncompressed and compressed size !!! if(dwRawBytesInThisSector < dwBytesInThisSector) { - int cbOutSector = dwBytesInThisSector; - int cbInSector = dwRawBytesInThisSector; - int nResult = 0; - - // Is the file compressed by Blizzard's multiple compression ? - if(pFileEntry->dwFlags & MPQ_FILE_COMPRESS) + if(dwRawBytesInThisSector != 0) { - // Remember the last used compression - hf->dwCompression0 = pbInSector[0]; - - // Decompress the data - if(ha->pHeader->wFormatVersion >= MPQ_FORMAT_VERSION_2) - nResult = SCompDecompress2(pbOutSector, &cbOutSector, pbInSector, cbInSector); - else - nResult = SCompDecompress(pbOutSector, &cbOutSector, pbInSector, cbInSector); - } + int cbOutSector = dwBytesInThisSector; + int cbInSector = dwRawBytesInThisSector; + int nResult = 0; - // Is the file compressed by PKWARE Data Compression Library ? - else if(pFileEntry->dwFlags & MPQ_FILE_IMPLODE) - { - nResult = SCompExplode(pbOutSector, &cbOutSector, pbInSector, cbInSector); - } + // Is the file compressed by Blizzard's multiple compression ? + if(pFileEntry->dwFlags & MPQ_FILE_COMPRESS) + { + // Remember the last used compression + hf->dwCompression0 = pbInSector[0]; + + // Decompress the data + if(ha->pHeader->wFormatVersion >= MPQ_FORMAT_VERSION_2) + nResult = SCompDecompress2(pbOutSector, &cbOutSector, pbInSector, cbInSector); + else + nResult = SCompDecompress(pbOutSector, &cbOutSector, pbInSector, cbInSector); + } + + // Is the file compressed by PKWARE Data Compression Library ? + else if(pFileEntry->dwFlags & MPQ_FILE_IMPLODE) + { + nResult = SCompExplode(pbOutSector, &cbOutSector, pbInSector, cbInSector); + } - // Did the decompression fail ? - if(nResult == 0) + // Did the decompression fail ? + if(nResult == 0) + { + dwErrCode = ERROR_FILE_CORRUPT; + break; + } + } + else { - dwErrCode = ERROR_FILE_CORRUPT; - break; + memset(pbOutSector, 0, dwBytesInThisSector); } } else |