shithub: freetype+ttf2subf

Download patch

ref: 7925edcef4d53c272ef60bc8e7ae631409b6190e
parent: 5bbb4940087afe9e6cf6fff14133f7f5d6c59b2f
author: Werner Lemberg <[email protected]>
date: Thu May 30 15:29:41 EDT 2002

* src/bdf/bdflib.c (_bdf_readstream): Allocate `buf' dynamically.
(_bdf_parse_glyphs): Use correct size for allocating
`font->unencoded'.
(bdf_load_font): Free array conditionally.
Return proper error code in case of failure.
* src/bdf/bdfdrivr.c (BDF_Face_Init): Make it more robust against
unusual fonts.

git/fs: mount .git/fs: mount/attach disallowed
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2002-05-29  Detlef W�rkner  <[email protected]>
+
+	* src/bdf/bdflib.c (_bdf_readstream): Allocate `buf' dynamically.
+	(_bdf_parse_glyphs): Use correct size for allocating
+	`font->unencoded'.
+	(bdf_load_font): Free array conditionally.
+	Return proper error code in case of failure.
+	* src/bdf/bdfdrivr.c (BDF_Face_Init): Make it more robust against
+	unusual fonts.
+
 2002-05-29  Werner Lemberg  <[email protected]>
 
 	* src/bdf/descrip.mms, src/type42/descrip.mms: New files.
--- a/src/bdf/bdfdrivr.c
+++ b/src/bdf/bdfdrivr.c
@@ -128,9 +128,10 @@
       prop = bdf_get_font_property( font, (char *)"SPACING" );
       if ( prop != NULL )
         if ( prop->format == BDF_ATOM )
-          if ( ( *(prop->value.atom) == 'M' ) ||
-               ( *(prop->value.atom) == 'C' ) )
-            root->face_flags |= FT_FACE_FLAG_FIXED_WIDTH;
+          if ( prop->value.atom != NULL )
+            if ( ( *(prop->value.atom) == 'M' ) ||
+                 ( *(prop->value.atom) == 'C' ) )
+              root->face_flags |= FT_FACE_FLAG_FIXED_WIDTH;
 
       /* FZ XXX: TO DO: FT_FACE_FLAGS_VERTICAL   */
       /* FZ XXX: I need a font to implement this */
@@ -139,18 +140,20 @@
       prop = bdf_get_font_property( font, (char *)"SLANT" );
       if ( prop != NULL )
         if ( prop->format == BDF_ATOM )
-          if ( ( *(prop->value.atom) == 'O' ) ||
-               ( *(prop->value.atom) == 'I' ) )
-            root->style_flags |= FT_STYLE_FLAG_ITALIC;
+          if ( prop->value.atom != NULL )
+            if ( ( *(prop->value.atom) == 'O' ) ||
+                 ( *(prop->value.atom) == 'I' ) )
+              root->style_flags |= FT_STYLE_FLAG_ITALIC;
 
       prop = bdf_get_font_property( font, (char *)"WEIGHT_NAME" );
       if ( prop != NULL )
         if ( prop->format == BDF_ATOM )
-          if ( *(prop->value.atom) == 'B' )
-            root->style_flags |= FT_STYLE_FLAG_BOLD;
+          if ( prop->value.atom != NULL )
+            if ( *(prop->value.atom) == 'B' )
+              root->style_flags |= FT_STYLE_FLAG_BOLD;
 
       prop = bdf_get_font_property( font, (char *)"FAMILY_NAME" );
-      if ( prop != NULL )
+      if ( ( prop != NULL ) && ( prop->value.atom != NULL ) )
       {
         int  l = ft_strlen( prop->value.atom ) + 1;
 
@@ -237,7 +240,9 @@
         if ( ( charset_registry != NULL ) && ( charset_encoding != NULL ) )
         {
           if ( ( charset_registry->format == BDF_ATOM ) &&
-               ( charset_encoding->format == BDF_ATOM ) )
+               ( charset_encoding->format == BDF_ATOM ) &&
+               ( charset_registry->value.atom != NULL ) &&
+               ( charset_encoding->value.atom != NULL ) )
           {
             if ( FT_NEW_ARRAY( face->charset_encoding,
                                strlen( charset_encoding->value.atom ) + 1 ) )
--- a/src/bdf/bdflib.c
+++ b/src/bdf/bdflib.c
@@ -643,8 +643,8 @@
     unsigned long     lineno;
     int               n, res, done, refill, bytes, hold;
     char              *ls, *le, *pp, *pe, *hp;
-    /* XXX: Use a dynamic buffer */
-    char              buf[65536L];
+    char              *buf = 0;
+    FT_Memory         memory = stream->memory;
     FT_Error          error = BDF_Err_Ok;
 
 
@@ -654,6 +654,9 @@
       goto Exit;
     }
 
+    if ( FT_NEW_ARRAY( buf, 65536L ) )
+      goto Exit;
+
     cb     = callback;
     lineno = 1;
     buf[0] = 0;
@@ -732,6 +735,7 @@
     *lno             = lineno;
 
   Exit:
+    FT_FREE( buf );
     return error;
   }
 
@@ -1619,7 +1623,7 @@
           {
             if ( font->unencoded_size == 0 )
             {
-              if ( FT_NEW_ARRAY( font->unencoded, 2 ) )
+              if ( FT_NEW_ARRAY( font->unencoded, 4 ) )
                 goto Exit;
             }
             else
@@ -2290,7 +2294,8 @@
     }
 
     /* Free up the list used during the parsing. */
-    FT_FREE( p.list.field );
+    if ( memory != NULL )
+      FT_FREE( p.list.field );
 
     if ( p.font != 0 )
     {
@@ -2306,6 +2311,8 @@
         p.font->comments[p.font->comments_len] = 0;
       }
     }
+    else if ( error == BDF_Err_Ok )
+      error = BDF_Err_Invalid_File_Format;
 
     *font = p.font;