From 8d169943eb4421b6bf3165ff42d9444f282fb03c Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Tue, 12 Apr 2016 13:39:18 +0200 Subject: [PATCH] QWindowsLocalCodec::convertFromUnicode(): preclude stack overflow. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This method is called by QString::toLocal8Bit_helper(), so using QString::toLocal8Bit() on the input in an error message on failure to decode would be apt to recurse on the same data (if such an error ever arises). Furthermore, the qWarning()'s format string even claimed what it was displaying was in UTF-8. Fix by using native fprintf and UTF-16. Thanks to Frédéric Marchal for spotting this and checking that such errors aren't (at present) possible. Change-Id: I1ad441f2e3700bc01256d6c1718d404e27bce488 Reviewed-by: Thiago Macieira --- src/corelib/codecs/qwindowscodec.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/corelib/codecs/qwindowscodec.cpp b/src/corelib/codecs/qwindowscodec.cpp index dded93ccb54..a7c6f724221 100644 --- a/src/corelib/codecs/qwindowscodec.cpp +++ b/src/corelib/codecs/qwindowscodec.cpp @@ -208,10 +208,12 @@ QByteArray QWindowsLocalCodec::convertFromUnicode(const QChar *ch, int uclen, Co 0, 0, 0, &used_def)); // and try again... } else { + // Fail. Probably can't happen in fact (dwFlags is 0). #ifndef QT_NO_DEBUG - // Fail. - qWarning("WideCharToMultiByte: Cannot convert multibyte text (error %d): %s (UTF-8)", - r, QString(ch, uclen).toLocal8Bit().data()); + // Can't use qWarning(), as it'll recurse to handle %ls + fprintf(stderr, + "WideCharToMultiByte: Cannot convert multibyte text (error %d): %ls\n", + r, reinterpret_cast(QString(ch, uclen).utf16())); #endif break; }