diff options
| author | Ladislav Zezula <zezula@volny.cz> | 2024-04-21 18:56:43 +0200 | 
|---|---|---|
| committer | Ladislav Zezula <zezula@volny.cz> | 2024-04-21 18:56:43 +0200 | 
| commit | f70bfc0eb6eaf09fe653d55b977efcbb25bf4a00 (patch) | |
| tree | ee17189e84534b11aaa1c019022e21c7e7b0736d | |
| parent | dccc1068b0246697b70af2d7b6f8f7418d623324 (diff) | |
Fixed division by zero in https://github.com/ladislav-zezula/StormLib/issues/335
| -rw-r--r-- | src/SFileOpenArchive.cpp | 10 | ||||
| -rwxr-xr-x | test/StormTest.cpp | 8 | 
2 files changed, 11 insertions, 7 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);      } diff --git a/test/StormTest.cpp b/test/StormTest.cpp index 84ed667..290c419 100755 --- a/test/StormTest.cpp +++ b/test/StormTest.cpp @@ -3788,13 +3788,11 @@ static DWORD TestReplaceFile(LPCTSTR szMpqPlainName, LPCTSTR szFilePlainName, LP  static void Test_PlayingSpace()
  {
  /*
 -    SFILE_FIND_DATA sf;
      HANDLE hMpq = NULL;
 -    if(SFileOpenArchive(_T("e:\\poc11"), 0, 0, &hMpq))
 +    if(SFileOpenArchive(_T("e:\\poc17"), 0, 0, &hMpq))
      {
 -        SFileFindFirstFile(hMpq, "*", &sf, NULL);
 -        SFileAddWave(hMpq, _T("e:\\Ladik\\Incoming\\poc11"), "poc11", MPQ_FILE_FIX_KEY, 1);
 +        SFileCompactArchive(hMpq, _T("e:\\Ladik\\Incoming\\poc17"), true);
          SFileCloseArchive(hMpq);
      }
  */
 @@ -4009,6 +4007,8 @@ static const TEST_INFO1 Test_OpenMpqs[] =      //{_T("pocs/MPQ_2024_05_HeapOverflow.mpq"),                   NULL, "0539ae020719654a0ea6e2627a8195f8",    14},
      {_T("pocs/MPQ_2024_06_HeapOverflowReadFile.mpq"),           NULL, "d41d8cd98f00b204e9800998ecf8427e",     1},
      {_T("pocs/MPQ_2024_07_InvalidBitmapFooter.mpq"),            NULL, "--------------------------------",     TFLG_WILL_FAIL},
 +    {_T("pocs/MPQ_2024_08_InvalidSectorSize.mpq"),              NULL, "--------------------------------",     TFLG_WILL_FAIL},
 +    {_T("pocs/MPQ_2024_09_InvalidSectorSize.mpq"),              NULL, "--------------------------------",     TFLG_WILL_FAIL},
      // Correct or damaged archives
      {_T("MPQ_1997_v1_Diablo1_DIABDAT.MPQ"),                     NULL, "554b538541e42170ed41cb236483489e",  2910, &TwoFilesD1},  // Base MPQ from Diablo 1
  | 
