Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/SMemUtf8.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ const unsigned char SMemCharToByte[0x80] =
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF // 0x70
};

static TCHAR szInvalidCharPrefix[] = _T("%u[");

//-----------------------------------------------------------------------------
// Local functions

Expand Down Expand Up @@ -217,7 +219,7 @@ static size_t UTF8_FlushInvalidChars(LPTSTR szBuffer, size_t ccBuffer, size_t nO
// Space for 4 characters needed
if(szBuffer != NULL && (nOutLength + nLengthNeeded) <= ccBuffer)
{
memcpy(szBuffer + nOutLength, _T("%u["), 6);
memcpy(szBuffer + nOutLength, szInvalidCharPrefix, sizeof(szInvalidCharPrefix) - sizeof(TCHAR));

SMemBinToStr(szBuffer + nOutLength + 3, ccBuffer - 3, InvalidChars, nInvalidChars);

Expand Down
7 changes: 5 additions & 2 deletions test/StormTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1436,9 +1436,12 @@ static DWORD LoadMpqFile(TLogHelper & Logger, HANDLE hMpq, LPCSTR szFileName, LC
DWORD dwBytesRead;
DWORD dwCrc32 = 0;
DWORD dwErrCode = ERROR_SUCCESS;
TCHAR szSafeName[1024];

// Do nothing if the file name is invalid
Logger.PrintProgress("Loading file %s ...", GetShortPlainName(szFileName));
// Print the file name to the console.
// Prevent bad UTF-8 sequences to go through
SMemUTF8ToFileName(szSafeName, _countof(szSafeName), szFileName, NULL, 0, NULL);
Logger.PrintProgress(_T("Loading file %s ..."), GetShortPlainName(szSafeName));

#if defined(_MSC_VER) && defined(_DEBUG)
//if(!_stricmp(szFileName, "(signature)"))
Expand Down
2 changes: 1 addition & 1 deletion test/stormlib-test-001.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ TestReadingMpq (MPQ_2023_v4_UTF8.s2ma) succeeded.
TestReadingMpq (MPQ_2023_v1_GreenTD.w3x) succeeded.
TestReadingMpq (MPQ_2023_v4_1F644C5A.SC2Replay) succeeded.
TestReadingMpq (<Chinese MPQ name>) succeeded.
TestReadingMpq (MPQ_2024_v1_BadUtf8_5.0.2.w3x) succeeded. ... ..
TestReadingMpq (MPQ_2024_v1_BadUtf8_5.0.2.w3x) succeeded.
TestReadingMpq (MPQ_2002_v1_ProtectedMap_InvalidUserData.w3x) succeeded.
TestReadingMpq (MPQ_2002_v1_ProtectedMap_InvalidMpqFormat.w3x) succeeded.
TestReadingMpq (MPQ_2002_v1_ProtectedMap_Spazzler.w3x) succeeded.
Expand Down