freetype-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Devel] BDF fixes


From: Detlef Würkner
Subject: [Devel] BDF fixes
Date: Thu, 30 May 2002 11:00:19 +0200

I wrote:

> The following patch fixes
> - the too large stack problem of my compiler
> - the "ps not declared" problem
> - the problem that the BDF driver could crash here with an input file
>   of 4 bytes in length (this depends on which modules are used, if
>   the BDF driver was the only font driver it could be reproduced).
[...]
> However, I still have BDF font files here that let the driver crash.

Doesnt happen anymore with this patch which contains the above fixes plus
- a fix for a wrong-sized array which could crash the driver
- fixes for avoiding to read zero pointers while parsing unusual BDF fonts
  (with e.g. SLANT="")

----8<----
--- freetype2-current/src/bdf/bdflib.c.ori      Wed May 29 08:45:54 2002
+++ freetype2-current/src/bdf/bdflib.c  Thu May 30 07:27:44 2002
@@ -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
@@ -1740,10 +1744,6 @@
         /* the scalable width from the device width.                      */
         FT_TRACE2(( "_bdf_parse_glyphs: " ACMSG9, lineno ));
 
-        ps = (double)font->point_size;
-        rx = (double)font->resolution_x;
-        dw = (double)glyph->dwidth;
-
         glyph->swidth = (unsigned short)FT_MulDiv(
                           glyph->dwidth, 72000L,
                           (FT_Long)( font->point_size *
@@ -2294,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 )
     {
@@ -2310,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;
 
--- freetype2-current/src/bdf/bdfdrivr.c.ori    Wed May 22 05:41:06 2002
+++ freetype2-current/src/bdf/bdfdrivr.c        Thu May 30 08:16:08 2002
@@ -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 ) )
----8<----

Ciao, Detlef
-- 
_ // address@hidden
\X/  Detlef Wuerkner, Langgoens/Germany



reply via email to

[Prev in Thread] Current Thread [Next in Thread]