Avoid overflow in text layout

Fixes oss-fuzz issue 29313.

Pick-to: 6.0 5.15
Change-Id: Idbabd162fa9e0dbce687981bdbcc75be37189a61
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
Reviewed-by: Robert Löhning <robert.loehning@qt.io>
This commit is contained in:
Eirik Aavitsland 2021-01-26 17:29:08 +01:00
parent 07c248a594
commit bfc09b8d8f
2 changed files with 17 additions and 0 deletions

View File

@ -820,6 +820,10 @@ QTextLine QTextLayout::createLine()
int l = d->lines.size();
if (l && d->lines.at(l-1).length < 0) {
QTextLine(l-1, d).setNumColumns(INT_MAX);
if (d->maxWidth > QFIXED_MAX / 2) {
qWarning("QTextLayout: text too long, truncated.");
return QTextLine();
}
}
int from = l > 0 ? d->lines.at(l-1).from + d->lines.at(l-1).length + d->lines.at(l-1).trailingSpaces : 0;
int strlen = d->layoutData->string.length();

View File

@ -1895,6 +1895,19 @@ void tst_QTextLayout::longText()
QVERIFY(line.isValid());
QVERIFY(line.cursorToX(line.textLength() - 1) > 0);
}
{
QTextLayout layout(QString("Qt rocks! ").repeated(200000));
layout.setCacheEnabled(true);
layout.beginLayout();
forever {
QTextLine line = layout.createLine();
if (!line.isValid())
break;
}
layout.endLayout();
QVERIFY(layout.maximumWidth() <= QFIXED_MAX);
}
}
void tst_QTextLayout::widthOfTabs()