On Tue, 23 Apr 2019 22:08:30 +0200
"Silvan Jegen" <[email protected]> wrote:

Dear Silvan,

> From what I can tell, returning 1 in this case won't work because st
> calls die() when xloadfont returns non-0 at all call sites. We would
> have to load a fallback font instead, I think.

the failure case here is a result of bad user input (as the user
specified a font string that contains a colour font), but I agree that
this is better moved one level up so we can error out and say "better
not specify colour fonts, as it leads to crashes easily), at least
print a warn() or something, but I just kept a die() here.

> The dwm patch for for this issue [0] also adds this call to choose the
> fallback font.
> 
> +     FcPatternAddBool(fcpattern, FC_COLOR, FcFalse);
> 
> We probably have to do the same in st.

This is a really good point! See attached version 2 of my patch
reflecting your suggestions.

With best regards

Laslo

-- 
Laslo Hunhold <[email protected]>
>From 9aad206ca079fb556e916304cd2249384a6485fb Mon Sep 17 00:00:00 2001
From: Laslo Hunhold <[email protected]>
Date: Tue, 23 Apr 2019 10:02:14 +0200
Subject: [PATCH] Work around BadLength error by disallowing color fonts

This problem has given us enough trouble on the ML alone and is a
bug in the Xft library that probably won't ever be fixed.

This change is a port of Anselm's commit to dwm
(cb3f58ad06993f7ef3a7d8f61468012e2b786cab) and with input
from Silvan Jegen.
---
 LICENSE |  4 ++--
 x.c     | 13 +++++++++++++
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/LICENSE b/LICENSE
index c356c39..07518e3 100644
--- a/LICENSE
+++ b/LICENSE
@@ -4,7 +4,7 @@ MIT/X Consortium License
 © 2018 Devin J. Pohly <djpohly at gmail dot com>
 © 2014-2017 Quentin Rameau <quinq at fifth dot space>
 © 2009-2012 Aurélien APTEL <aurelien dot aptel at gmail dot com>
-© 2008-2017 Anselm R Garbe <garbeam at gmail dot com>
+© 2008-2019 Anselm R Garbe <garbeam at gmail dot com>
 © 2012-2017 Roberto E. Vargas Caballero <k0ga at shike2 dot com>
 © 2012-2016 Christoph Lohmann <20h at r-36 dot net>
 © 2013 Eon S. Jeon <esjeon at hyunmu dot am>
@@ -13,7 +13,7 @@ MIT/X Consortium License
 © 2013-2014 Eric Pruitt <eric.pruitt at gmail dot com>
 © 2013 Michael Forney <mforney at mforney dot org>
 © 2013-2014 Markus Teich <markus dot teich at stusta dot mhn dot de>
-© 2014-2015 Laslo Hunhold <dev at frign dot de>
+© 2014-2019 Laslo Hunhold <dev at frign dot de>
 
 Permission is hereby granted, free of charge, to any person obtaining a
 copy of this software and associated documentation files (the "Software"),
diff --git a/x.c b/x.c
index 5828a3b..a3347d4 100644
--- a/x.c
+++ b/x.c
@@ -910,6 +910,7 @@ xloadfont(Font *f, FcPattern *pattern)
 void
 xloadfonts(char *fontstr, double fontsize)
 {
+	FcBool iscol;
 	FcPattern *pattern;
 	double fontval;
 
@@ -944,6 +945,17 @@ xloadfonts(char *fontstr, double fontsize)
 		defaultfontsize = usedfontsize;
 	}
 
+	/* Do not allow using color fonts. This is a workaround for a BadLength
+	 * error from Xft with color glyphs. Modelled on the Xterm workaround. See
+	 * https://bugzilla.redhat.com/show_bug.cgi?id=1498269
+	 * https://lists.suckless.org/dev/1701/30932.html
+	 * https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=916349
+	 * and lots more all over the internet.
+	 */
+	if(FcPatternGetBool(pattern, FC_COLOR, 0, &iscol) == FcResultMatch && iscol) {
+		die("Xft causes crashes with color fonts like '%s'\n", fontstr);
+	}
+
 	if (xloadfont(&dc.font, pattern))
 		die("can't open font %s\n", fontstr);
 
@@ -1235,6 +1247,7 @@ xmakeglyphfontspecs(XftGlyphFontSpec *specs, const Glyph *glyphs, int len, int x
 			FcPatternAddCharSet(fcpattern, FC_CHARSET,
 					fccharset);
 			FcPatternAddBool(fcpattern, FC_SCALABLE, 1);
+			FcPatternAddBool(fcpattern, FC_COLOR, 0);
 
 			FcConfigSubstitute(0, fcpattern,
 					FcMatchPattern);
-- 
2.21.0

Attachment: pgpbNfyDrHRem.pgp
Description: PGP signature

Reply via email to