From 413cd06c88d4ccc5e1383d5f1f556fd35333dcbc Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Thu, 13 Jan 2022 09:13:48 +0100 Subject: [PATCH] Fix crash when text shaping fails If text shaping failed for some reason (for example if the string passed to Harfbuzz contains ignorables only), we would return a single glyph for the whole string. But we forgot to initialize the log clusters array, which could cause crashes later when this was read. We initialize a single cluster consisting of the "missing glyph" glyph to be consistent. Amends fccd419dd632306a4bd85928223e0a56a59510ef. [ChangeLog][QtGui][Text] Fixed a possible crash with certain fonts when shaping strings consisting only of control characters. Pick-to: 5.15 6.2 6.3 Task-number: QTBUG-89155 Fixes: QTBUG-92358 Change-Id: I1ec0237d99b48be2a8bb340f0feb056bca4fdffe Reviewed-by: Lars Knoll Reviewed-by: Konstantin Ritt Reviewed-by: Qt CI Bot --- src/gui/text/qtextengine.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/gui/text/qtextengine.cpp b/src/gui/text/qtextengine.cpp index 14e44f56d9e..9e294d083e7 100644 --- a/src/gui/text/qtextengine.cpp +++ b/src/gui/text/qtextengine.cpp @@ -1564,6 +1564,12 @@ void QTextEngine::shapeText(int item) const // Overwrite with 0 token to indicate failure QGlyphLayout g = availableGlyphs(&si); g.glyphs[0] = 0; + g.attributes[0].clusterStart = true; + + ushort *log_clusters = logClusters(&si); + for (int i = 0; i < itemLength; ++i) + log_clusters[i] = 0; + return; }