From d5cd2ae9cbfd5f1e0e9d2d0cd738fbb1e9a3de16 Mon Sep 17 00:00:00 2001 From: dgrfactory Date: Wed, 5 Feb 2025 01:05:46 +0900 Subject: [PATCH] refs ignore SNESAPU.DLL MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Script700 の追加読み込み時のバッファサイズ計算を追加 --- snesapu.dll/thirdparty/SNESAPU.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/snesapu.dll/thirdparty/SNESAPU.cpp b/snesapu.dll/thirdparty/SNESAPU.cpp index 8993881..4e2e803 100644 --- a/snesapu.dll/thirdparty/SNESAPU.cpp +++ b/snesapu.dll/thirdparty/SNESAPU.cpp @@ -288,7 +288,7 @@ void IncludeScript700File(u32 addr, u32 value, void *lpData) { if (_700Asc) { // get buffer size - if (_700DirSize + value > 2048) { + if (_700DirSize + value >= 2048) { FreeLibrary(hModule); free(lp700File); return; @@ -300,8 +300,16 @@ void IncludeScript700File(u32 addr, u32 value, void *lpData) { LoadScript700(func, lp700File, addr); } else { // get buffer size + u32 cchWideChar = MultiByteToWideChar(CP_ACP, NULL, (LPCSTR)lpData, -1, NULL, NULL); + if (_700DirSize + cchWideChar + cchWideChar + 2 >= 2048) { + FreeLibrary(hModule); + free(lp700File); + return; + } + + // ansi to wide char void *lpFile = (void*)((u32)lp700File + _700DirSize); - u32 result = MultiByteToWideChar(CP_ACP, NULL, (LPCSTR)lpData, -1, (LPWSTR)lpFile, 2048 - _700DirSize); + u32 result = MultiByteToWideChar(CP_ACP, NULL, (LPCSTR)lpData, -1, (LPWSTR)lpFile, cchWideChar); if (!result) { FreeLibrary(hModule); free(lp700File);