From f2b7d064b04f20c7100231d8db2ef067d33f2c43 Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Fri, 29 Nov 2024 15:02:26 +0100 Subject: [PATCH] Fix assert in certain cases of missing glyph in a string If a substring for a fallback engine spanned multiple characters, we would only assign the first of the characters to a glyph in log clusters. This could cause the log clusters array to become non-monotonic (you could get an array like [0, 1, 2, 0, 3, 4]). In turn, this would confuse the text layout algorithm which depends on the indexes always increasing, and we would sometimes hit an assert in addNextCluster() if we were unlucky. To rectify this, make sure all characters in the substring are mapped to the same cluster. Fixes: QTBUG-131731 Pick-to: 6.5 5.15 Change-Id: I93415a58351349ead6eb7a016b32b09f274e6fe4 Reviewed-by: Lars Knoll (cherry picked from commit 40e364172f001ce7dd6e4e72716e9c17c9d29b9e) --- src/gui/text/qtextengine.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/gui/text/qtextengine.cpp b/src/gui/text/qtextengine.cpp index 08512bead57..8c4f9608d17 100644 --- a/src/gui/text/qtextengine.cpp +++ b/src/gui/text/qtextengine.cpp @@ -1747,7 +1747,8 @@ int QTextEngine::shapeTextWithHarfbuzzNG(const QScriptItem &si, g.offsets[0].y = QFixed{}; g.attributes[0].clusterStart = true; g.attributes[0].dontPrint = true; - log_clusters[0] = glyphs_shaped; + for (uint str_pos = 0; str_pos < item_length; ++str_pos) + log_clusters[str_pos] = glyphs_shaped; } if (Q_UNLIKELY(engineIdx != 0)) {