diff --git a/src/tools/balooshow/main.cpp b/src/tools/balooshow/main.cpp --- a/src/tools/balooshow/main.cpp +++ b/src/tools/balooshow/main.cpp @@ -200,17 +200,40 @@ QHash propertyWords; for (const QByteArray& arr : terms) { + auto arrAsPrintable = [arr]() { + return QString::fromLatin1(arr.toPercentEncoding()); + }; + + if (arr.length() < 1) { + stream << i18n("Internal Error - %1", QString("malformed term (short): '%1'\n").arg(arrAsPrintable())); + continue; + } QString word = QString::fromUtf8(arr); if (word[0].isUpper()) { if (word[0] == QLatin1Char('X')) { - int posOfNonNumeric = 1; - while (word[posOfNonNumeric] != '-') { - posOfNonNumeric++; + if (word.length() < 4) { + // 'X- + stream << i18n("Internal Error - %1", + QString("malformed property term (short): '%1' in '%2'\n").arg(word).arg(arrAsPrintable())); + continue; + } + int posOfNonNumeric = word.indexOf('-', 2); + if ((posOfNonNumeric < 0) || ((posOfNonNumeric + 1) == word.length())) { + stream << i18n("Internal Error - %1", + QString("malformed property term (no data): '%1' in '%2'\n").arg(word).arg(arrAsPrintable())); + continue; } - int propNum = word.midRef(1, posOfNonNumeric-1).toInt(); + bool ok; + QStringRef prop = word.midRef(1, posOfNonNumeric-1); + int propNum = prop.toInt(&ok); QString value = word.mid(posOfNonNumeric + 1); + if (!ok) { + stream << i18n("Internal Error - %1", + QString("malformed property term (bad index): '%1' in '%2'\n").arg(prop).arg(arrAsPrintable())); + continue; + } propertyWords[propNum].append(value); }