Subject: bug#41627: 28.0.50; Emacs with cairo build segfault in HELLO file

From: Pip Cet <[email-masked]>
Date: Sun, 31 May 2020 12:35:07 +0000

On Sun, May 31, 2020 at 11:49 AM Zihao Zhu <[email-masked]> wrote:
> I try the Emacs build in commit
> 780f674a82a90c4e3e32583059b498bfa57e4a06. When I eval
>
> (set-frame-font "Sarasa Mono Slab SC" t)

> GDB attached backtrace in attachment.

This line seems suspicious:

        font_face = 0x7ffff747e880 <_cairo_font_face_nil_file_not_found>

It looks like you can't rely on cairo_ft_font_face_create_for_pattern
to return a NULL pointer. I suspect the attached patch will work, but
if this is something Cairo does in other places it needs to be
checked.

(My suspicion is the font was not installed correctly, so Cairo
couldn't find it.)
From 6b40e4b1c2c5376f9ad819aacdd32d142fb5e67b Mon Sep 17 00:00:00 2001
From: Pip Cet <[email-masked]>
Date: Sun, 31 May 2020 12:31:50 +0000
Subject: [PATCH] Handle the case that Cairo cannot find a font file
 (Bug#41627)

* src/ftcrfont.c (ftcrfont_open): Handle non-NULL error returns
from cairo_ft_font_face_create_for_pattern.
---
 src/ftcrfont.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/ftcrfont.c b/src/ftcrfont.c
index 7832d4f5ce..ec87ae3335 100644
--- a/src/ftcrfont.c
+++ b/src/ftcrfont.c
@@ -139,7 +139,8 @@ ftcrfont_open (struct frame *f, Lisp_Object entity, int pixel_size)
 
   FcPatternDestroy (pat);
   font_face = cairo_ft_font_face_create_for_pattern (match);
-  if (!font_face)
+  if (!font_face
+      || cairo_font_face_status (font_face) != CAIRO_STATUS_SUCCESS)
     {
       unblock_input ();
       FcPatternDestroy (match);
-- 
2.27.0.rc0