Subject: bug#37786: 26.3; Emacs crashes when calling function to decode string

From: Robert Pluim <[email-masked]>
Date: Tue, 05 Nov 2019 18:40:28 +0100

>>>>> On Sun, 27 Oct 2019 09:26:35 +0100, Robert Pluim <[email-masked]> said:

>>>>> On Sat, 26 Oct 2019 02:44:52 -0700, Allen Li <[email-masked]> said:
    >>> Hmm. Could you try the following against emacs-26 and see if it fixes
    >>> your crash? (the character will almost certainly end up displayed
    >>> wrong). This looks more like a fontconfig bug than anything else: the
    >>> pattern we've supplied to FcFontList explicitly says "donʼt give me
    >>> color fonts".

    Allen> Yep, this fixes the crash and I get the box with unicode codepoint
    Allen> inside.  I don't know anything about fontconfig, so I can't comment on
    Allen> whether this is a fontconfig bug.

    Robert> Thanks for testing. Iʼll have to write a standalone test case against
    Robert> fontconfig before I can say whether itʼs a fontconfig bug or not, in
    Robert> the meantime Iʼll clean up the patch.

I think itʼs a fontconfig bug, but Iʼve received no response from the
fontconfig guys. Perhaps I need to use their new-fangled issue tracker
thing rather than good old email. In any case, both Arch and Fedora 31
have fontconfig packages with this issue, so we need to paper^Wfix the
issue our end.

>From aabd13bba282563410ef95764cad39f02ecb5d84 Mon Sep 17 00:00:00 2001
From: Robert Pluim <[email-masked]>
Date: Mon, 4 Nov 2019 17:44:57 +0100
Subject: [PATCH] Ignore color fonts returned from FcFontList
To: [email-masked]

* src/ftfont.c (ftfont_list): [HAVE_XFT && FC_COLOR]: Ask FcFontList
to return FC_COLOR attribute.  Check returned attribute for
non-FcFalse, since some color fonts have a color attribute that's
neither FcFalse nor FcTrue (Bug#37786).
---
 src/ftfont.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/src/ftfont.c b/src/ftfont.c
index 77a4cf5de5..b066f55a18 100644
--- a/src/ftfont.c
+++ b/src/ftfont.c
@@ -864,6 +864,9 @@ ftfont_list (struct frame *f, Lisp_Object spec)
 #endif	/* FC_CAPABILITY */
 #ifdef FC_FONTFORMAT
 			     FC_FONTFORMAT,
+#endif
+#if defined HAVE_XFT && defined FC_COLOR
+                             FC_COLOR,
 #endif
 			     NULL);
   if (! objset)
@@ -904,7 +907,19 @@ ftfont_list (struct frame *f, Lisp_Object spec)
   for (i = 0; i < fontset->nfont; i++)
     {
       Lisp_Object entity;
-
+#if defined HAVE_XFT && defined FC_COLOR
+      {
+        /* Some fonts, notably NotoColorEmoji, have an FC_COLOR value
+           that's neither FcTrue nor FcFalse, which means FcFontList
+           returns them even when it shouldn't really do so, so we
+           need to manually skip them here (Bug#37786).  */
+        FcBool b;
+        if (Vxft_ignore_color_fonts
+            && FcPatternGetBool (fontset->fonts[i], FC_COLOR, 0, &b)
+            == FcResultMatch && b != FcFalse)
+            continue;
+      }
+#endif
       if (spacing >= 0)
 	{
 	  int this;
-- 
2.19.1.816.gcd69ec8cde