Commit e1ca18d4492d819e2deeb4302a9d3ed037f64ebb

Werner Lemberg 2015-10-17T11:51:27

[bdf] Use stream size to adjust number of glyphs. * src/bdf/bdflib.c (ACMSG17): New message macro. (_bdf_parse_t): Add member `size'. (bdf_load_font): Set `size'. (_bdf_parse_glyphs): Adjust `cnt' if necessary.

diff --git a/ChangeLog b/ChangeLog
index 0971afc..2374771 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,14 @@
 2015-10-17  Werner Lemberg  <wl@gnu.org>
 
+	[bdf] Use stream size to adjust number of glyphs.
+
+	* src/bdf/bdflib.c (ACMSG17): New message macro.
+	(_bdf_parse_t): Add member `size'.
+	(bdf_load_font): Set `size'.
+	(_bdf_parse_glyphs): Adjust `cnt' if necessary.
+
+2015-10-17  Werner Lemberg  <wl@gnu.org>
+
 	* src/cid/cidload.c (cid_parse_dict): Check `[FG]DBytes' size.
 
 2015-10-17  Werner Lemberg  <wl@gnu.org>
diff --git a/src/bdf/bdflib.c b/src/bdf/bdflib.c
index 5b1beef..4f3b4fd 100644
--- a/src/bdf/bdflib.c
+++ b/src/bdf/bdflib.c
@@ -201,6 +201,7 @@
 #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"
+#define ACMSG17  "Adjusting number of glyphs to %ld.\n"
 
   /* Error messages. */
 #define ERRMSG1  "[line %ld] Missing `%s' line.\n"
@@ -432,6 +433,7 @@
     _bdf_list_t     list;
 
     FT_Memory       memory;
+    unsigned long   size;        /* the stream size */
 
   } _bdf_parse_t;
 
@@ -1579,6 +1581,13 @@
         goto Exit;
       p->cnt = font->glyphs_size = _bdf_atoul( p->list.field[1], 0, 10 );
 
+      /* We need at least 20 bytes per glyph. */
+      if ( p->cnt > p->size / 20 )
+      {
+        p->cnt = p->size / 20;
+        FT_TRACE2(( "_bdf_parse_glyphs: " ACMSG17, p->cnt ));
+      }
+
       /* Make sure the number of glyphs is non-zero. */
       if ( p->cnt == 0 )
         font->glyphs_size = 64;
@@ -2447,6 +2456,7 @@
     memory    = NULL;
     p->opts   = (bdf_options_t*)( ( opts != 0 ) ? opts : &_bdf_opts );
     p->minlb  = 32767;
+    p->size   = stream->size;
     p->memory = extmemory;  /* only during font creation */
 
     _bdf_list_init( &p->list, extmemory );