From 05c43ed7ab8eca002538670970cff4edb66f1011 Mon Sep 17 00:00:00 2001 From: Manuel Nickschas Date: Sat, 1 Mar 2014 14:07:36 +0100 Subject: [PATCH] Don't crash on very long inputs Because our style engine uses 16 bit indexes, strings can only be styled if they're shorter than 2^16 characters. We do check for this in the style engine and refuse to style strings that are longer. However, just returning an default-constructed StyledString() is wrong, because other places rely on there being at least one format and the plaintext be initialized. So the proper way of handling this is just using the baseFormat and the full string as plaintext instead of an empty StyledString. Fixes #1257. --- src/uisupport/uistyle.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/uisupport/uistyle.cpp b/src/uisupport/uistyle.cpp index dd530bd3..8c5ce840 100644 --- a/src/uisupport/uistyle.cpp +++ b/src/uisupport/uistyle.cpp @@ -491,12 +491,16 @@ QList UiStyle::toTextLayoutList(const FormatList &form UiStyle::StyledString UiStyle::styleString(const QString &s_, quint32 baseFormat) { QString s = s_; + StyledString result; + result.formatList.append(qMakePair((quint16)0, baseFormat)); + if (s.length() > 65535) { + // We use quint16 for indexes qWarning() << QString("String too long to be styled: %1").arg(s); - return StyledString(); + result.plainText = s; + return result; } - StyledString result; - result.formatList.append(qMakePair((quint16)0, baseFormat)); + quint32 curfmt = baseFormat; int pos = 0; quint16 length = 0; for (;;) { -- 2.20.1