Skip to content

Commit 80ddc8d

Browse files
committed
Fix crash when fontconfig fallback pattern has no charset
QFontEngineMultiFontConfig::shouldLoadFontEngineForCharacter() passed the address of an uninitialized FcCharSet* to FcPatternGetCharSet() and then called FcCharSetHasChar() on it without checking the result. A pattern returned by FcFontMatch() is not guaranteed to carry an FC_CHARSET element: fontconfig treats the charset as optional, and caches produced by other fontconfig builds (e.g. a bundled snapshot that indexed .woff/.woff2 files it could not parse as empty patterns) can legally serve charset-less patterns. In that case the uninitialized pointer is dereferenced inside FcCharSetHasChar() and the process crashes with SIGSEGV; builds hardened with -ftrivial-auto-var-init=pattern crash deterministically at 0xfefe... Observed in the wild on Arch/Manjaro after the fontconfig 2.18.1 upgrade: every Qt application (Qt Creator, CopyQ, KeePassXC, ...) crashed in FcCharSetHasChar via QFontEngineMulti::glyphIndex() as soon as any glyph fallback lookup ran, because stale fontconfig caches served a charset-less pattern for every FcFontMatch() call. Initialize the pointer and check the FcPatternGetCharSet() result. When no charset can be obtained, keep the optimistic default (load the engine) exactly as we already do when no match pattern is available, so glyph coverage is decided by the font engine itself. Pick-to: 6.12 6.11 6.8 Change-Id: I18687e0a7b7a0019a459155395636768ad9ea964 Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
1 parent bd7909f commit 80ddc8d

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

‎src/gui/text/unix/qfontenginemultifontconfig.cpp‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@ bool QFontEngineMultiFontConfig::shouldLoadFontEngineForCharacter(int at, uint u
2525
bool charSetHasChar = true;
2626
FcPattern *matchPattern = getMatchPatternForFallback(at - 1);
2727
if (matchPattern != nullptr) {
28-
FcCharSet *charSet;
29-
FcPatternGetCharSet(matchPattern, FC_CHARSET, 0, &charSet);
30-
charSetHasChar = FcCharSetHasChar(charSet, ucs4);
28+
FcCharSet *charSet = nullptr;
29+
if (FcPatternGetCharSet(matchPattern, FC_CHARSET, 0, &charSet) == FcResultMatch
30+
&& charSet != nullptr) {
31+
charSetHasChar = FcCharSetHasChar(charSet, ucs4);
32+
}
3133
}
3234

3335
return charSetHasChar;

0 commit comments

Comments
 (0)