aboutsummaryrefslogtreecommitdiff
path: root/src/SFileOpenArchive.cpp
diff options
context:
space:
mode:
authorLadislav Zezula <zezula@volny.cz>2024-04-21 18:56:43 +0200
committerLadislav Zezula <zezula@volny.cz>2024-04-21 18:56:43 +0200
commitf70bfc0eb6eaf09fe653d55b977efcbb25bf4a00 (patch)
treeee17189e84534b11aaa1c019022e21c7e7b0736d /src/SFileOpenArchive.cpp
parentdccc1068b0246697b70af2d7b6f8f7418d623324 (diff)
Fixed division by zero in https://github.com/ladislav-zezula/StormLib/issues/335
Diffstat (limited to 'src/SFileOpenArchive.cpp')
-rw-r--r--src/SFileOpenArchive.cpp10
1 files changed, 7 insertions, 3 deletions
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);
}