From bdd0c17e1e527685c9d70122eb9ec88be8135d07 Mon Sep 17 00:00:00 2001 From: typpos <28550406+typpos@users.noreply.github.com> Date: Tue, 2 Feb 2021 07:18:44 +1100 Subject: [PATCH] (#503) Fix sandboxie.ini corruption by 3-byte UTF-8 chars. --- Sandboxie/core/svc/sbieiniserver.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Sandboxie/core/svc/sbieiniserver.cpp b/Sandboxie/core/svc/sbieiniserver.cpp index 3a6cee4c..1ffc23f4 100644 --- a/Sandboxie/core/svc/sbieiniserver.cpp +++ b/Sandboxie/core/svc/sbieiniserver.cpp @@ -1462,8 +1462,9 @@ ULONG SbieIniServer::RefreshConf() char* text_utf8 = NULL; if (IsUTF8) { - text_utf8 = (char*)HeapAlloc(GetProcessHeap(), 0, lenToWrite + 16); - lenToWrite = WideCharToMultiByte(CP_UTF8, 0, m_text_base, lenToWrite / sizeof(WCHAR), text_utf8, lenToWrite + 16, NULL, NULL); + ULONG utf8_len = WideCharToMultiByte(CP_UTF8, 0, m_text_base, lenToWrite / sizeof(WCHAR), NULL, 0, NULL, NULL); + text_utf8 = (char*)HeapAlloc(GetProcessHeap(), 0, utf8_len); + lenToWrite = WideCharToMultiByte(CP_UTF8, 0, m_text_base, lenToWrite / sizeof(WCHAR), text_utf8, utf8_len, NULL, NULL); } ULONG lenWritten = 0;