mlang/tests: Add test for multibyte string truncation mlang: Fix bug when multibyte string truncation in ConvertINetMultiByteToUnicode
Signed-off-by: YeshunYe yeyeshun@uniontech.com
-- v6: Update file mlang.c
From: YeshunYe yeyeshun@uniontech.com
Signed-off-by: YeshunYe yeyeshun@uniontech.com --- dlls/mlang/tests/mlang.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)
diff --git a/dlls/mlang/tests/mlang.c b/dlls/mlang/tests/mlang.c index d104d4d5184..c9f6f450c0e 100644 --- a/dlls/mlang/tests/mlang.c +++ b/dlls/mlang/tests/mlang.c @@ -567,7 +567,11 @@ static void test_multibyte_to_unicode_translations(IMultiLanguage2 *iML2) { /* these APIs are broken regarding constness of the input buffer */ char stringA[] = "Just a test string\0"; /* double 0 for CP_UNICODE tests */ + char bad936A_end[] = "test\xb2\xe2\xca\xd4"; + char bad936A_mid[] = "test\xb2\x31\xca\xd4"; WCHAR stringW[] = {'J','u','s','t',' ','a',' ','t','e','s','t',' ','s','t','r','i','n','g',0}; + WCHAR bad936W_end[] = {'t','e','s','t',0x6d4b,0}; + WCHAR bad936W_mid[] = {'t','e','s','t','?',0x8bd5,0}; char bufA[256]; WCHAR bufW[256]; UINT lenA, lenW, expected_len; @@ -644,6 +648,27 @@ static void test_multibyte_to_unicode_translations(IMultiLanguage2 *iML2) expected_len = MultiByteToWideChar(1252, 0, stringA, lenA, NULL, 0); ok(lenW == expected_len, "expected lenW %u, got %u\n", expected_len, lenW);
+ memset(bufW, 'x', sizeof(bufW)); + lenA = lstrlenA(bad936A_end); + lenA -= 1; /* chinese character truncation */ + lenW = ARRAY_SIZE(bufW); + ret = pConvertINetMultiByteToUnicode(NULL, 936, bad936A_end, (INT *)&lenA, bufW, (INT *)&lenW); + ok(ret == S_OK, "ConvertINetMultiByteToUnicode failed: %08lx\n", ret); + todo_wine ok(lenA == lstrlenA(bad936A_end) - 2, "expected lenA %u, got %u\n", lstrlenA(bad936A_end) - 2, lenA); + expected_len = MultiByteToWideChar(936, 0, bad936A_end, lenA, NULL, 0); + ok(lenW == expected_len, "expected lenW %u, got %u\n", expected_len, lenW); + todo_wine ok(!memcmp(bufW, bad936W_end, lenW * sizeof(WCHAR)), "bufW/stringW mismatch\n"); + + memset(bufW, 'x', sizeof(bufW)); + lenA = lstrlenA(bad936A_mid); + lenW = ARRAY_SIZE(bufW); + ret = pConvertINetMultiByteToUnicode(NULL, 936, bad936A_mid, (INT *)&lenA, bufW, (INT *)&lenW); + ok(ret == S_OK, "ConvertINetMultiByteToUnicode failed: %08lx\n", ret); + todo_wine ok(lenA == lstrlenA(bad936A_mid), "expected lenA %u, got %u\n", lstrlenA(bad936A_mid), lenA); + expected_len = MultiByteToWideChar(936, 0, bad936A_mid, lenA, NULL, 0); + ok(lenW == expected_len, "expected lenW %u, got %u\n", expected_len, lenW); + todo_wine ok(!memcmp(bufW, bad936W_mid, lenW * sizeof(WCHAR)), "bufW/stringW mismatch\n"); + /* IMultiLanguage2_ConvertStringFromUnicode tests */
memset(bufA, 'x', sizeof(bufA));
From: YeshunYe yeyeshun@uniontech.com
Signed-off-by: YeshunYe yeyeshun@uniontech.com --- dlls/mlang/mlang.c | 25 ++++++++++++++++++++++++- dlls/mlang/tests/mlang.c | 8 ++++---- 2 files changed, 28 insertions(+), 5 deletions(-)
diff --git a/dlls/mlang/mlang.c b/dlls/mlang/mlang.c index e340a5f57c7..968f118d52a 100644 --- a/dlls/mlang/mlang.c +++ b/dlls/mlang/mlang.c @@ -983,7 +983,30 @@ HRESULT WINAPI ConvertINetMultiByteToUnicode( default: if (*pcSrcSize == -1) *pcSrcSize = lstrlenA(pSrcStr); - + if (*pcSrcSize) + { + int cursor = 0; + CPINFOEXA info = { 0 }; + GetCPInfoExA(dwEncoding, 0, &info); + if (info.CodePage == 932 || info.CodePage == 936 || + info.CodePage == 949 || info.CodePage == 950 || + info.CodePage == 1361) + { + while (cursor < *pcSrcSize) + { + if (IsDBCSLeadByte(pSrcStr[cursor])) + { + cursor++; + if (cursor >= *pcSrcSize) + { + *pcSrcSize = cursor - 1; + break; + } + } + cursor++; + } + } + } if (pDstStr) *pcDstSize = MultiByteToWideChar(dwEncoding, 0, pSrcStr, *pcSrcSize, pDstStr, *pcDstSize); else diff --git a/dlls/mlang/tests/mlang.c b/dlls/mlang/tests/mlang.c index c9f6f450c0e..e52440cd079 100644 --- a/dlls/mlang/tests/mlang.c +++ b/dlls/mlang/tests/mlang.c @@ -654,20 +654,20 @@ static void test_multibyte_to_unicode_translations(IMultiLanguage2 *iML2) lenW = ARRAY_SIZE(bufW); ret = pConvertINetMultiByteToUnicode(NULL, 936, bad936A_end, (INT *)&lenA, bufW, (INT *)&lenW); ok(ret == S_OK, "ConvertINetMultiByteToUnicode failed: %08lx\n", ret); - todo_wine ok(lenA == lstrlenA(bad936A_end) - 2, "expected lenA %u, got %u\n", lstrlenA(bad936A_end) - 2, lenA); + ok(lenA == lstrlenA(bad936A_end) - 2, "expected lenA %u, got %u\n", lstrlenA(bad936A_end) - 2, lenA); expected_len = MultiByteToWideChar(936, 0, bad936A_end, lenA, NULL, 0); ok(lenW == expected_len, "expected lenW %u, got %u\n", expected_len, lenW); - todo_wine ok(!memcmp(bufW, bad936W_end, lenW * sizeof(WCHAR)), "bufW/stringW mismatch\n"); + ok(!memcmp(bufW, bad936W_end, lenW * sizeof(WCHAR)), "bufW/stringW mismatch\n");
memset(bufW, 'x', sizeof(bufW)); lenA = lstrlenA(bad936A_mid); lenW = ARRAY_SIZE(bufW); ret = pConvertINetMultiByteToUnicode(NULL, 936, bad936A_mid, (INT *)&lenA, bufW, (INT *)&lenW); ok(ret == S_OK, "ConvertINetMultiByteToUnicode failed: %08lx\n", ret); - todo_wine ok(lenA == lstrlenA(bad936A_mid), "expected lenA %u, got %u\n", lstrlenA(bad936A_mid), lenA); + ok(lenA == lstrlenA(bad936A_mid), "expected lenA %u, got %u\n", lstrlenA(bad936A_mid), lenA); expected_len = MultiByteToWideChar(936, 0, bad936A_mid, lenA, NULL, 0); ok(lenW == expected_len, "expected lenW %u, got %u\n", expected_len, lenW); - todo_wine ok(!memcmp(bufW, bad936W_mid, lenW * sizeof(WCHAR)), "bufW/stringW mismatch\n"); + ok(!memcmp(bufW, bad936W_mid, lenW * sizeof(WCHAR)), "bufW/stringW mismatch\n");
/* IMultiLanguage2_ConvertStringFromUnicode tests */
From: Yeshun Ye yeyeshun@uniontech.com
--- dlls/mlang/mlang.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/dlls/mlang/mlang.c b/dlls/mlang/mlang.c index 968f118d52a..98c863a64d8 100644 --- a/dlls/mlang/mlang.c +++ b/dlls/mlang/mlang.c @@ -990,7 +990,9 @@ HRESULT WINAPI ConvertINetMultiByteToUnicode( GetCPInfoExA(dwEncoding, 0, &info); if (info.CodePage == 932 || info.CodePage == 936 || info.CodePage == 949 || info.CodePage == 950 || - info.CodePage == 1361) + info.CodePage == 1361 || dwEncoding == 932 || + dwEncoding == 936 || dwEncoding == 949 || + dwEncoding == 950 || dwEncoding == 1361) { while (cursor < *pcSrcSize) {
Hi,
It looks like your patch introduced the new failures shown below. Please investigate and fix them before resubmitting your patch. If they are not new, fixing them anyway would help a lot. Otherwise please ask for the known failures list to be updated.
The tests also ran into some preexisting test failures. If you know how to fix them that would be helpful. See the TestBot job for the details:
The full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=148007
Your paranoid android.
=== debian11 (32 bit report) ===
mlang: mlang.c:657: Test failed: expected lenA 6, got 7 mlang.c:660: Test failed: bufW/stringW mismatch
=== debian11 (32 bit ar:MA report) ===
mlang: mlang.c:657: Test failed: expected lenA 6, got 7 mlang.c:660: Test failed: bufW/stringW mismatch
=== debian11 (32 bit de report) ===
mlang: mlang.c:657: Test failed: expected lenA 6, got 7 mlang.c:660: Test failed: bufW/stringW mismatch
=== debian11 (32 bit fr report) ===
mlang: mlang.c:657: Test failed: expected lenA 6, got 7 mlang.c:660: Test failed: bufW/stringW mismatch
=== debian11 (32 bit he:IL report) ===
mlang: mlang.c:657: Test failed: expected lenA 6, got 7 mlang.c:660: Test failed: bufW/stringW mismatch
=== debian11 (32 bit hi:IN report) ===
mlang: mlang.c:657: Test failed: expected lenA 6, got 7 mlang.c:660: Test failed: bufW/stringW mismatch
=== debian11 (32 bit ja:JP report) ===
mlang: mlang.c:657: Test failed: expected lenA 6, got 7 mlang.c:660: Test failed: bufW/stringW mismatch
=== debian11b (32 bit WoW report) ===
mlang: mlang.c:657: Test failed: expected lenA 6, got 7 mlang.c:660: Test failed: bufW/stringW mismatch
=== debian11b (64 bit WoW report) ===
mlang: mlang.c:657: Test failed: expected lenA 6, got 7 mlang.c:660: Test failed: bufW/stringW mismatch
user32: input.c:4305: Test succeeded inside todo block: button_down_hwnd_todo 1: got MSG_TEST_WIN hwnd 0000000001D600FE, msg WM_LBUTTONDOWN, wparam 0x1, lparam 0x320032