From 731b3a804f3ea39ac7a6ce98d2ca260c9040c9e6 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 21 Apr 2019 20:05:37 +0200 Subject: [PATCH] Return error from wxConvAuto if not given enough bytes Instead of falling back on Latin-1 if we fail to decode the input as UTF-8, check if we have enough bytes for the latter and just return an error if we don't. This ensures that wxTextInputStream::GetChar() and similar code will retry with a longer byte sequence, allowing wxConvAuto to be used for decoding UTF-8 contents on the fly, which didn't work before. See #14720. --- src/common/convauto.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/common/convauto.cpp b/src/common/convauto.cpp index 6a5fba4ecb..a9fe15cb2d 100644 --- a/src/common/convauto.cpp +++ b/src/common/convauto.cpp @@ -309,6 +309,13 @@ wxConvAuto::ToWChar(wchar_t *dst, size_t dstLen, size_t rc = m_conv->ToWChar(dst, dstLen, src, srcLen); if ( rc == wxCONV_FAILED && m_bomType == wxBOM_None ) { + // we may need more bytes before we can decode the input, don't switch + // 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 + if ( srcLen < m_conv->GetMaxCharLen() ) + return wxCONV_FAILED; + // if the conversion failed but we didn't really detect anything and // simply tried UTF-8 by default, retry it using the fall-back if ( m_encDefault != wxFONTENCODING_MAX )