From f70bfc0eb6eaf09fe653d55b977efcbb25bf4a00 Mon Sep 17 00:00:00 2001 From: Ladislav Zezula Date: Sun, 21 Apr 2024 18:56:43 +0200 Subject: Fixed division by zero in https://github.com/ladislav-zezula/StormLib/issues/335 --- src/SFileOpenArchive.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'src/SFileOpenArchive.cpp') diff --git a/src/SFileOpenArchive.cpp b/src/SFileOpenArchive.cpp index a97ecea..587aa96 100644 --- a/src/SFileOpenArchive.cpp +++ b/src/SFileOpenArchive.cpp @@ -501,10 +501,14 @@ bool WINAPI SFileOpenArchive( break; } - // Set the size of file sector - ha->dwSectorSize = (0x200 << ha->pHeader->wSectorSize); + // Set the size of file sector. Be sure to check for integer overflow + if((ha->dwSectorSize = (0x200 << ha->pHeader->wSectorSize)) == 0) + dwErrCode = ERROR_FILE_CORRUPT; + } - // Verify if any of the tables doesn't start beyond the end of the file + // Verify if any of the tables doesn't start beyond the end of the file + if(dwErrCode == ERROR_SUCCESS) + { dwErrCode = VerifyMpqTablePositions(ha, FileSize); } -- cgit v1.2.3