Keith Packard <[email protected]> writes:

> Oh, right. Sorry.

Here's the updated commit message and comment text.

From ba3e118bd0c7efd492f3204537b06da6a610fa52 Mon Sep 17 00:00:00 2001
From: Keith Packard <[email protected]>
Date: Tue, 8 Apr 2014 11:20:59 -0700
Subject: [PATCH] glamor: Work around libXfont when it fails to use defaultChar

GetGlyphs is supposed to always return the full list of characters
when there is a default character available. However, if an
application opens a 16-bit two dimensional font and then draws with
8-bit requests, the bitmapGetGlyphs function in libXfont versions up
through 1.4.7 will return zero glyphs if there is no 0th row.

While this is a bug in libXfont and should be fixed there, it's easy
to protect glamor from it by simply falling through to the case that
handles GetGlyphs failures for fonts without a default character.

Signed-off-by: Keith Packard <[email protected]>
---
 glamor/glamor_text.c | 34 ++++++++++++++++++++++++----------
 1 file changed, 24 insertions(+), 10 deletions(-)

diff --git a/glamor/glamor_text.c b/glamor/glamor_text.c
index 395116d..aa63d1a 100644
--- a/glamor/glamor_text.c
+++ b/glamor/glamor_text.c
@@ -37,6 +37,7 @@ glamor_get_glyphs(FontPtr font, glamor_font_t *glamor_font,
     unsigned long nglyphs;
     FontEncoding encoding;
     int char_step;
+    int c;
 
     if (sixteen) {
         char_step = 2;
@@ -49,7 +50,7 @@ glamor_get_glyphs(FontPtr font, glamor_font_t *glamor_font,
         encoding = Linear8Bit;
     }
 
-    /* If the font has a default character, then we don't have to
+    /* If the font has a default character, then we shouldn't have to
      * worry about missing glyphs, so just get the whole string all at
      * once. Otherwise, we have to fetch chars one at a time to notice
      * missing ones.
@@ -57,15 +58,28 @@ glamor_get_glyphs(FontPtr font, glamor_font_t *glamor_font,
     if (glamor_font->default_char) {
         GetGlyphs(font, (unsigned long) count, (unsigned char *) chars,
                   encoding, &nglyphs, charinfo);
-    } else {
-        int c;
-        for (c = 0; c < count; c++) {
-            GetGlyphs(font, 1, (unsigned char *) chars,
-                      encoding, &nglyphs, &charinfo[c]);
-            if (!nglyphs)
-                charinfo[c] = NULL;
-            chars += char_step;
-        }
+
+        /* Make sure it worked. There's a bug in libXfont through
+         * version 1.4.7 which would cause it to fail when the font is
+         * a 2D font without a first row, and the application sends a
+         * 1-d request. In this case, libXfont would return zero
+         * glyphs, even when the font had a default character.
+         *
+         * It's easy enough for us to work around that bug here by
+         * simply checking the returned nglyphs and falling through to
+         * the one-at-a-time code below. Not doing this check would
+         * result in uninitialized memory accesses in the rendering code.
+         */
+        if (nglyphs == count)
+            return;
+    }
+
+    for (c = 0; c < count; c++) {
+        GetGlyphs(font, 1, (unsigned char *) chars,
+                  encoding, &nglyphs, &charinfo[c]);
+        if (!nglyphs)
+            charinfo[c] = NULL;
+        chars += char_step;
     }
 }
 
-- 
2.0.0.rc0

-- 
[email protected]

Attachment: pgpCsTXaekYDz.pgp
Description: PGP signature

_______________________________________________
[email protected]: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: http://lists.x.org/mailman/listinfo/xorg-devel

Reply via email to