Commit 5b591e49cf3c87fddeb44acc8a6b6d3a4fbda31a

Werner Lemberg 2007-06-01T22:16:43

* include/freetype/fterrdef.h (FT_Err_Corrupted_Font_Header, FT_Err_Corrupted_Font_Glyphs): New error codes for BDF files. * src/bdf/bdflib.c (bdf_load_font): Use them. * src/bdf/bdflib.c (_bdf_parse_start): Check `FONT' better.

diff --git a/ChangeLog b/ChangeLog
index 4852321..d9bb6bc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2007-06-02  Werner Lemberg  <wl@gnu.org>
+
+	* include/freetype/fterrdef.h (FT_Err_Corrupted_Font_Header,
+	FT_Err_Corrupted_Font_Glyphs): New error codes for BDF files.
+
+	* src/bdf/bdflib.c (bdf_load_font): Use them.
+
+	* src/bdf/bdflib.c (_bdf_parse_start): Check `FONT' better.
+
 2007-06-01  Werner Lemberg  <wl@gnu.org>
 
 	* src/base/ftobjs.c (FT_Request_Metrics), src/cache/ftccmap.c
diff --git a/include/freetype/fterrdef.h b/include/freetype/fterrdef.h
index ab8c3f7..d7ad256 100644
--- a/include/freetype/fterrdef.h
+++ b/include/freetype/fterrdef.h
@@ -4,7 +4,7 @@
 /*                                                                         */
 /*    FreeType error codes (specification).                                */
 /*                                                                         */
-/*  Copyright 2002, 2004, 2006 by                                          */
+/*  Copyright 2002, 2004, 2006, 2007 by                                    */
 /*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
 /*                                                                         */
 /*  This file is part of the FreeType project, and may only be used,       */
@@ -230,6 +230,10 @@
                 "`BBX' field missing" )
   FT_ERRORDEF_( Bbx_Too_Big,                                 0xB7, \
                 "`BBX' too big" )
+  FT_ERRORDEF_( Corrupted_Font_Header,                       0xB8, \
+                "Font header corrupted or missing fields" )
+  FT_ERRORDEF_( Corrupted_Font_Glyphs,                       0xB9, \
+                "Font glyphs corrupted or missing fields" )
 
 
 /* END */
diff --git a/src/bdf/bdflib.c b/src/bdf/bdflib.c
index 8dade71..512cd62 100644
--- a/src/bdf/bdflib.c
+++ b/src/bdf/bdflib.c
@@ -2123,6 +2123,13 @@
       _bdf_list_shift( &p->list, 1 );
 
       s = _bdf_list_join( &p->list, ' ', &slen );
+
+      if ( !s )
+      {
+        error = BDF_Err_Invalid_File_Format;
+        goto Exit;
+      }
+
       if ( FT_NEW_ARRAY( p->font->name, slen + 1 ) )
         goto Exit;
       FT_MEM_COPY( p->font->name, s, slen + 1 );
@@ -2307,11 +2314,19 @@
       {
         /* The ENDFONT field was never reached or did not exist. */
         if ( !( p->flags & _BDF_GLYPHS ) )
+        {
           /* Error happened while parsing header. */
           FT_ERROR(( "bdf_load_font: " ERRMSG2, lineno ));
+          error = BDF_Err_Corrupted_Font_Header;
+          goto Exit;
+        }
         else
+        {
           /* Error happened when parsing glyphs. */
           FT_ERROR(( "bdf_load_font: " ERRMSG3, lineno ));
+          error = BDF_Err_Corrupted_Font_Glyphs;
+          goto Exit;
+        }
       }
     }