Opened 7 years ago

Last modified 7 years ago

#11848 assigned Bugs

Win32 backend bug when do wide char convert to multi byte in boost::locale

Reported by: fyrestone@… Owned by: Artyom Beilis
Milestone: To Be Determined Component: locale
Version: Boost 1.59.0 Severity: Problem
Keywords: Cc:

Description

The function wide_to_multibyte_non_zero in locale/src/encoding/wconv_codepage.ipp has bug. This function assume that when the codepage is CP_UTF7 or CP_UTF8, the substitute_ptr and subst_char_ptr will be 0. But, in x64 Windows 10, I use codepage 54936 get 87 error code after the first WideCharToMultiByte called. This will make n is zero, and the second WideCharToMultiByte call will make the program crash.

In MSDN shipped with Visual Studio .NET 2003 it is said that parameters lpDefaultChar and lpUsedDefaultChar must be NULL not only for CP_UTF7 and CP_UTF8, but also for all codepages mentioned in notes for dwFlags parameter:

50220 50221 50222 50225 50227 50229 57002 through 57011 65000 (UTF-7) 42 (Symbol)

It is still true as of Windows 8 & 10: if you try to call

BOOL bVal = FALSE;

WideCharToMultiByte(50220, 0, L"asdf", 4, NULL, 0, NULL, &bVal);

You'll get 0 with GetLastError 87 (ERROR_INVALID_PARAMETER).

Change History (1)

comment:1 by Artyom Beilis, 7 years ago

Status: newassigned

It contradicts MSDN:

https://msdn.microsoft.com/en-us/library/windows/desktop/dd374130(v=vs.85).aspx

(yes I know in comments it is mentioned)

Also the reason you crash is because &buf[0] can't be called when n==0 (in first place)

I'll look into it.

Thanks.

Note: See TracTickets for help on using tickets.