Re: [hackers] [st] [PATCHv2] Work around BadLength error by disallowing color fonts

2019-04-23 Thread Laslo Hunhold
On Tue, 23 Apr 2019 22:08:30 +0200
"Silvan Jegen"  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 
>From 9aad206ca079fb556e916304cd2249384a6485fb Mon Sep 17 00:00:00 2001
From: Laslo Hunhold 
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 
 © 2014-2017 Quentin Rameau 
 © 2009-2012 Aurélien APTEL 
-© 2008-2017 Anselm R Garbe 
+© 2008-2019 Anselm R Garbe 
 © 2012-2017 Roberto E. Vargas Caballero 
 © 2012-2016 Christoph Lohmann <20h at r-36 dot net>
 © 2013 Eon S. Jeon 
@@ -13,7 +13,7 @@ MIT/X Consortium License
 © 2013-2014 Eric Pruitt 
 © 2013 Michael Forney 
 © 2013-2014 Markus Teich 
-© 2014-2015 Laslo Hunhold 
+© 2014-2019 Laslo Hunhold 
 
 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, ) == FcResultMatch && iscol) {
+		die("Xft causes crashes with color fonts like '%s'\n", fontstr);
+	}
+
 	if (xloadfont(, 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



pgpbNfyDrHRem.pgp
Description: PGP signature


Re: [hackers] [st] [PATCH] Work around BadLength error by disallowing color fonts

2019-04-23 Thread Silvan Jegen
Hi Laslo

Thanks for giving this a shot!

A comment below.

Laslo Hunhold  wrote:
> Dear fellow hackers,
> 
> this patch will hopefully resolve the many mails we get on dev@ and
> hackers@ regarding crashes of st due to emoji-fonts triggering some
> voodoo-condition in Xft.
> 
> I hope my port of Anselm's change to dwm to st is correct and would
> love to hear feedback.
> 
> With best regards
> 
> Laslo Hunhold
>
> [...]
> 
> diff --git a/x.c b/x.c
> index 5828a3b..074df47 100644
> --- a/x.c
> +++ b/x.c
> @@ -837,12 +837,24 @@ xgeommasktogravity(int mask)
>  int
>  xloadfont(Font *f, FcPattern *pattern)
>  {
> +   FcBool iscol;
> FcPattern *configured;
> FcPattern *match;
> FcResult result;
> XGlyphInfo extents;
> int wantattr, haveattr;
> 
> +   /* 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, ) == FcResultMatch && 
> iscol) {
> +   return 1;
> +   }
> +

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 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.


Cheers,

Silvan


[0] 
https://git.suckless.org/libsl/commit/53ebcb48c6b12882c6dbe352ee43c96b2fb01b84.html



[hackers] [st] [PATCH] Work around BadLength error by disallowing color fonts

2019-04-23 Thread Laslo Hunhold
Dear fellow hackers,

this patch will hopefully resolve the many mails we get on dev@ and
hackers@ regarding crashes of st due to emoji-fonts triggering some
voodoo-condition in Xft.

I hope my port of Anselm's change to dwm to st is correct and would
love to hear feedback.

With best regards

Laslo Hunhold

-- 
Laslo Hunhold 
>From 69cfb2193f5e7bb8dda42b3dc5474e3d04170ad1 Mon Sep 17 00:00:00 2001
From: Laslo Hunhold 
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).
---
 LICENSE |  4 ++--
 x.c | 12 
 2 files changed, 14 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 
 © 2014-2017 Quentin Rameau 
 © 2009-2012 Aurélien APTEL 
-© 2008-2017 Anselm R Garbe 
+© 2008-2019 Anselm R Garbe 
 © 2012-2017 Roberto E. Vargas Caballero 
 © 2012-2016 Christoph Lohmann <20h at r-36 dot net>
 © 2013 Eon S. Jeon 
@@ -13,7 +13,7 @@ MIT/X Consortium License
 © 2013-2014 Eric Pruitt 
 © 2013 Michael Forney 
 © 2013-2014 Markus Teich 
-© 2014-2015 Laslo Hunhold 
+© 2014-2019 Laslo Hunhold 
 
 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..074df47 100644
--- a/x.c
+++ b/x.c
@@ -837,12 +837,24 @@ xgeommasktogravity(int mask)
 int
 xloadfont(Font *f, FcPattern *pattern)
 {
+	FcBool iscol;
 	FcPattern *configured;
 	FcPattern *match;
 	FcResult result;
 	XGlyphInfo extents;
 	int wantattr, haveattr;
 
+	/* 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, ) == FcResultMatch && iscol) {
+		return 1;
+	}
+
 	/*
 	 * Manually configure instead of calling XftMatchFont
 	 * so that we can use the configured pattern for
-- 
2.21.0



pgphRfiDcoPen.pgp
Description: PGP signature