Commit 0b1c0c6b20bf121096afff206d570f26183402b3

Werner Lemberg 2012-02-25T10:23:04

[bdf] Fix Savannah bugs #35599 and #35600. * src/bdf/bdflib.c (ACMSG16): New warning message. (_bdf_parse_glyphs) <_BDF_BITMAP>: Check line length.

diff --git a/ChangeLog b/ChangeLog
index cf83e79..98df508 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2012-02-25  Werner Lemberg  <wl@gnu.org>
+
+	[bdf] Fix Savannah bugs #35599 and #35600.
+
+	* src/bdf/bdflib.c (ACMSG16): New warning message.
+	(_bdf_parse_glyphs) <_BDF_BITMAP>: Check line length.
+
 2012-02-24  Werner Lemberg  <wl@gnu.org>
 
 	[bdf] Fix Savannah bugs #35597 and #35598.
diff --git a/src/bdf/bdflib.c b/src/bdf/bdflib.c
index 37ffc1e..f2ca92d 100644
--- a/src/bdf/bdflib.c
+++ b/src/bdf/bdflib.c
@@ -188,6 +188,7 @@
 #define ACMSG13  "Glyph %ld extra rows removed.\n"
 #define ACMSG14  "Glyph %ld extra columns removed.\n"
 #define ACMSG15  "Incorrect glyph count: %ld indicated but %ld found.\n"
+#define ACMSG16  "Glyph %ld missing columns padded with zero bits.\n"
 
   /* Error messages. */
 #define ERRMSG1  "[line %ld] Missing `%s' line.\n"
@@ -1725,18 +1726,31 @@
       for ( i = 0; i < nibbles; i++ )
       {
         c = line[i];
+        if ( !c )
+          break;
         *bp = (FT_Byte)( ( *bp << 4 ) + a2i[c] );
         if ( i + 1 < nibbles && ( i & 1 ) )
           *++bp = 0;
       }
 
+      /* If any line has not enough columns,            */
+      /* indicate they have been padded with zero bits. */
+      if ( i < nibbles                            &&
+           !( p->flags & _BDF_GLYPH_WIDTH_CHECK ) )
+      {
+        FT_TRACE2(( "_bdf_parse_glyphs: " ACMSG16, glyph->encoding ));
+        p->flags       |= _BDF_GLYPH_WIDTH_CHECK;
+        font->modified  = 1;
+      }
+
       /* Remove possible garbage at the right. */
       mask_index = ( glyph->bbx.width * p->font->bpp ) & 7;
       if ( glyph->bbx.width )
         *bp &= nibble_mask[mask_index];
 
       /* If any line has extra columns, indicate they have been removed. */
-      if ( ( line[nibbles] == '0' || a2i[(int)line[nibbles]] != 0 ) &&
+      if ( i == nibbles                                             &&
+           ( line[nibbles] == '0' || a2i[(int)line[nibbles]] != 0 ) &&
            !( p->flags & _BDF_GLYPH_WIDTH_CHECK )                   )
       {
         FT_TRACE2(( "_bdf_parse_glyphs: " ACMSG14, glyph->encoding ));