Discussion:
[dev] Xft(?) bug with emoji
Alexander Krotov
2018-08-09 00:18:42 UTC
Permalink
I have reduced dmenu segfault down to a simple program:
https://bugs.freedesktop.org/show_bug.cgi?id=107531

Please read the program and see if you can tell what is wrong or
confirm a bug. Apparently the bug is in fontconfig.

Running dwm with "pango" patch doesn't help either, so I think the
problem is in fontconfig and not Xft.

Also there are many bugfixes since 2.13.0 related to null ponter
dereferences, so maybe the bug is already fixed:
https://cgit.freedesktop.org/fontconfig/log/
Hiltjo Posthuma
2018-08-09 09:12:27 UTC
Permalink
Post by Alexander Krotov
https://bugs.freedesktop.org/show_bug.cgi?id=107531
Please read the program and see if you can tell what is wrong or
confirm a bug. Apparently the bug is in fontconfig.
Running dwm with "pango" patch doesn't help either, so I think the
problem is in fontconfig and not Xft.
Also there are many bugfixes since 2.13.0 related to null ponter
https://cgit.freedesktop.org/fontconfig/log/
/*
gcc bug.c -lX11 -lXft -I /usr/include/freetype2 -lfontconfig
*/
#include <stdio.h>
#include <X11/Xlib.h>
#include <X11/Xft/Xft.h>
int main(void) {
Display *dpy = XOpenDisplay(NULL);
if(dpy == NULL)
return 1;
int screen = DefaultScreen(dpy);
char *fontname = "monospace:size=10";
XftFont *xfont = XftFontOpenName(dpy, screen, fontname);
if(xfont == NULL) {
printf("Can't load font pattern");
return 1;
}
FcPattern *pattern = FcNameParse((FcChar8 *) fontname);
if (pattern == NULL) {
printf("Can't parse name to pattern");
return 1;
}
long utf8codepoint = 0x1F4D3; // notebook emoji
FcCharSet *fccharset = FcCharSetCreate ();
FcCharSetAddChar(fccharset, utf8codepoint);
FcPatternAddCharSet(pattern, FC_CHARSET, fccharset);
FcPatternAddBool(pattern, FC_SCALABLE, FcTrue);
FcConfigSubstitute(NULL, pattern, FcMatchPattern);
FcDefaultSubstitute(pattern);
FcResult result;
// drw.c uses XftFontMatch here
FcFontMatch (NULL, pattern, &result);
XCloseDisplay(dpy);
}
Thanks for providing a test-program.

I still cannot reproduce this bug on OpenBSD.

Do I need some specific font for it to crash? I've seen reports of issues with
the Google Noto Emoji font.

fc-match 'monospace:size=10' is 'DejaVu Sans Mono' here.

When I install Noto Emoji and change the fontname:
to:
char *fontname = "Noto Emoji";

it still does not crash however.


I don't think using Pango is a good test, also the Pango page says:
"Client side fonts using the FreeType and fontconfig
libraries, using HarfBuzz for complex-text handling. Rendering can be with with
Cairo or Xft libraries, or directly to an in-memory buffer with no additional
libraries.".
--
Kind regards,
Hiltjo
Alexander Krotov
2018-08-09 10:41:03 UTC
Permalink
Post by Hiltjo Posthuma
Thanks for providing a test-program.
I still cannot reproduce this bug on OpenBSD.
Do I need some specific font for it to crash? I've seen reports of issues with
the Google Noto Emoji font.
fc-match 'monospace:size=10' is 'DejaVu Sans Mono' here.
char *fontname = "Noto Emoji";
it still does not crash however.
"Client side fonts using the FreeType and fontconfig
libraries, using HarfBuzz for complex-text handling. Rendering can be with with
Cairo or Xft libraries, or directly to an in-memory buffer with no additional
libraries.".
Looks like there are two different bugs. I can reproduce segfault on
Debian, but on other systems there is an unrelated X error in dmenu.
Alexander Krotov
2018-08-09 10:46:01 UTC
Permalink
Attached is the result of running
printf '\xf0\x9f\x93\x93' | XFT_DEBUG=1 dmenu
Alexander Krotov
2018-08-09 11:23:12 UTC
Permalink
Here is the program to reproduce Xft bug with X11 error. OK1 is printed,
OK2 is not.

Just FYI that the bug is localized and it is not a dmenu problem at all.
Hiltjo Posthuma
2018-08-09 15:07:52 UTC
Permalink
Post by Alexander Krotov
Here is the program to reproduce Xft bug with X11 error. OK1 is printed,
OK2 is not.
Just FYI that the bug is localized and it is not a dmenu problem at all.
/*
gcc xftbug.c -lX11 -lXft -I /usr/include/freetype2 -lfontconfig
*/
#include <stdio.h>
#include <X11/Xlib.h>
#include <X11/Xft/Xft.h>
int main(void) {
Display *dpy = XOpenDisplay(NULL);
if(dpy == NULL)
return 1;
int screen = DefaultScreen(dpy);
char *fontname = "Noto Color Emoji";
XftFont *xfont = XftFontOpenName(dpy, screen, fontname);
if(xfont == NULL) {
printf("Can't load font pattern");
return 1;
}
XGlyphInfo ext;
XftTextExtentsUtf8(dpy, xfont, "\xf0\x9f\x93\x93", 4, &ext);
fprintf(stderr, "OK1\n");
XSync (dpy, False);
fprintf(stderr, "OK2\n");
XCloseDisplay(dpy);
}
I went to https://www.google.com/get/noto/help/install/ and downloaded
the 1.1GB ZIP file and extracted the 1.5GB of fonts.
Then installed the Noto Color Emoji and ran your program.

Output:
OK1
OK2


I hope someone realises the absurdity of this.
--
Kind regards,
Hiltjo
Alexander Krotov
2018-08-09 11:27:41 UTC
Permalink
Xft bug is submitted upstream:
https://bugs.freedesktop.org/show_bug.cgi?id=107534
Loading...