Make leading nulls a special case to avoid breaking decoding some short strings in fallback encoding

This commit is contained in:
Pavel Tyunin
2020-10-07 17:02:06 +03:00
parent b536457e07
commit 1cbcf24832
2 changed files with 14 additions and 2 deletions

View File

@@ -334,9 +334,12 @@ wxConvAuto::ToWChar(wchar_t *dst, size_t dstLen,
// to the fall-back conversion in this case as it would prevent us from
// decoding UTF-8 input when fed it byte by byte, as done by
// wxTextInputStream, for example
// 2 extra bytes are needed for inputs that start with 1 or 2 null bytes
// up to 2 extra bytes are needed for inputs that start with null bytes
// that look like the start of UTF-32BE BOM, but can be in UTF-8 too
if ( srcLen < 2 + m_conv->GetMaxCharLen() && wxIsUTF8Prefix(src, srcLen) )
size_t nNull = 0;
if ( srcLen != wxNO_LEN && srcLen >= 2 && !src[0] )
nNull = ( src[1]? 1 : 2 );
if ( srcLen < nNull + m_conv->GetMaxCharLen() && wxIsUTF8Prefix(src, srcLen) )
return wxCONV_FAILED;
// if the conversion failed but we didn't really detect anything and