https://bugs.winehq.org/show_bug.cgi?id=56160
Bug ID: 56160 Summary: Kernel32: Unable to determine encoding format without [BOM] sequence.(PROFILE_DetectTextEncoding) Product: Wine Version: 9.0-rc4 Hardware: x86-64 OS: Linux Status: UNCONFIRMED Severity: major Priority: P2 Component: kernel32 Assignee: wine-bugs@winehq.org Reporter: zmtong1988@gmail.com Distribution: ---
Question: 1. Open the [UTF-8] encoding file, and if there is no [BOM] sequence, recognize it as [ENCODING-ANSI] through [PROFILE-DetectTextEncoding] instead of [UTF-8]. 2. Open the [UTF-16 LE] encoding file, and if there is no [BOM] sequence, recognize it as [ENCODING-ANSI] through [PROFILE-DetectTextEncoding] instead of [UTF-16 LE].
Function execution process: [ dlls/kenel32/profile. c ] --> [ PROFILE_ Open ] -->[ PROFILE_ Load ] -->[ PROFILE-DetectTextEncoding ]
Description: Open a file in [UTF-16 LE] encoding format and execute [ PROFILE_ DetectTextEncoding ]always returns [ ENCODING-ANSI ], and subsequent parsing work cannot be completed according to the encoding format.
https://bugs.winehq.org/show_bug.cgi?id=56160
--- Comment #1 from Maotong Zhang zmtong1988@gmail.com --- Can call to open .ini file for testing
https://bugs.winehq.org/show_bug.cgi?id=56160
Zeb Figura z.figura12@gmail.com changed:
What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |NEEDINFO Ever confirmed|0 |1 CC| |z.figura12@gmail.com
--- Comment #2 from Zeb Figura z.figura12@gmail.com --- What application does this affect?
https://bugs.winehq.org/show_bug.cgi?id=56160
--- Comment #3 from Maotong Zhang zmtong1988@gmail.com --- (In reply to Zeb Figura from comment #2)
What application does this affect?
Wine compiles and generates [win. ini] and [system. ini] using [PROFILE_DetectTextEncoding] to determine that they are also of the [ENCODING_ANSI] type. This does not affect the usage, UTF-8 and ANSI are basically the same and can be parsed. If UTF-16 is used for parsing, there may be issues.
For example: When the program calls GetPrivateProfileSectionNamesW to retrieve the names of all sections in the . ini file (UTF-16 LE), an issue occurs. Function Procedure: [GetPrivateProfileSectionNamesW] -->[PROFILE_Open] -->[PROFILE_Load] -->[PROFILE_DetectTextEncoding]
Result: When executing [PROFILE_DetectTextEncoding], as there is no BOM sequence, it cannot be determined and returns [ENCODING_ANSI]. When calculating [PROFILE_Load], it is correct to use [ENCODING_ANSI] for calculation, which results in the inability to parse the file.
-------------------- static PROFILESECTION *PROFILE_Load(HANDLE hFile, ENCODING * pEncoding) { ...... len = dwFileSize; *pEncoding = PROFILE_DetectTextEncoding(buffer_base, &len); /* len is set to the number of bytes in the character marker. * we want to skip these bytes */ pBuffer = (char *)buffer_base + len; dwFileSize -= len;
switch (*pEncoding) { case ENCODING_ANSI: TRACE("ANSI encoding\n");
len = MultiByteToWideChar(CP_ACP, 0, pBuffer, dwFileSize, NULL, 0); szFile = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR)); if (!szFile) { HeapFree(GetProcessHeap(), 0, buffer_base); return NULL; } MultiByteToWideChar(CP_ACP, 0, pBuffer, dwFileSize, szFile, len); szEnd = szFile + len; break; ...... case ENCODING_UTF16LE: TRACE("UTF16 Little Endian encoding\n"); szFile = pBuffer; szEnd = (WCHAR *)((char *)pBuffer + dwFileSize); break; .... }
https://bugs.winehq.org/show_bug.cgi?id=56160
--- Comment #4 from Zeb Figura z.figura12@gmail.com --- What application are you trying to run with Wine, that is failing due to this bug?
https://bugs.winehq.org/show_bug.cgi?id=56160
--- Comment #5 from Maotong Zhang zmtong1988@gmail.com --- Created attachment 75853 --> https://bugs.winehq.org/attachment.cgi?id=75853 Test program
https://bugs.winehq.org/show_bug.cgi?id=56160
--- Comment #6 from Maotong Zhang zmtong1988@gmail.com --- Created attachment 75854 --> https://bugs.winehq.org/attachment.cgi?id=75854 程序代码 program code
https://bugs.winehq.org/show_bug.cgi?id=56160
Maotong Zhang zmtong1988@gmail.com changed:
What |Removed |Added ---------------------------------------------------------------------------- Attachment #75854|程序代码 program code |program code description| |
https://bugs.winehq.org/show_bug.cgi?id=56160
--- Comment #7 from Maotong Zhang zmtong1988@gmail.com --- Created attachment 75855 --> https://bugs.winehq.org/attachment.cgi?id=75855 test file
https://bugs.winehq.org/show_bug.cgi?id=56160
--- Comment #8 from Maotong Zhang zmtong1988@gmail.com --- (In reply to Zeb Figura from comment #4)
What application are you trying to run with Wine, that is failing due to this bug?
Test program : Created attachment 75853 [details]
program code : Created attachment 75854 [details]
test file :Created attachment 75855 [details]
run: Place the Test.ini file in the [ drive_c ] directory of the container. Run the test. exe file using Wine. View the results.
Result: The test program can read file contents under Windows, and using Wine is incorrect.
[PROFILE DetectTextEncoding] parsed [ENCODING ANSI] instead of the correct [UTF-16 LE] encoding, resulting in file read errors.
https://bugs.winehq.org/show_bug.cgi?id=56160
--- Comment #9 from Maotong Zhang zmtong1988@gmail.com --- (In reply to Zeb Figura from comment #4)
What application are you trying to run with Wine, that is failing due to this bug?
I tried to make a judgment when there was no BOM sequence, determine the corresponding file encoding format, but several attempts have failed. I don't know how to improve and determine the encoding format.
https://bugs.winehq.org/show_bug.cgi?id=56160
--- Comment #10 from Maotong Zhang zmtong1988@gmail.com --- (In reply to Zeb Figura from comment #4)
What application are you trying to run with Wine, that is failing due to this bug?
Can you guide me on how to fix this issue? Thank you~