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

From: Eli Zaretskii <[email-masked]>
Date: Sun, 31 May 2020 20:24:41 +0300

> Cc: [email-masked], Pip Cet <[email-masked]>
> From: Zihao Zhu <[email-masked]>
> Date: Sun, 31 May 2020 23:38:28 +0800
> 
> A gdb attached backtrace generated by Emacs build with CFLAGS=-O0 -g3 in 
> attachment

Thanks, I think the situation is clear.

> 0x00000000006c5a34 in ftcrfont_open (f=0xc192d0, entity=0x1300675, pixel_size=18) at ftcrfont.c:237
> 237	ftcrfont.c: 没有那个文件或目录.
> #0  0x00000000006c5a34 in ftcrfont_open (f=0xc192d0, entity=0x1300675, pixel_size=18) at ftcrfont.c:237

This crashes here:

  ft_face = cairo_ft_scaled_font_lock_face (scaled_font);
  if (XFIXNUM (AREF (entity, FONT_SIZE_INDEX)) == 0)
    {
      int upEM = ft_face->units_per_EM;  <<<<<<<<<<<<<<<<<<<<<

because cairo_ft_scaled_font_lock_face returned NULL:

>         ft_face = 0x0

That function is documented to be able to return NULL:

  Returns

  The FT_Face object for font, scaled appropriately, or NULL if
  scaled_font is in an error state (see cairo_scaled_font_status()) or
  there is insufficient memory.

So it sounds like we should see if scaled_font is "in an error state",
and in any case bail out if ft_face is NULL.

Can someone please propose a patch along these lines?  I cannot easily
test a Cairo build, so I won't try showing a patch.

Thanks.