shithub: freetype+ttf2subf

Download patch

ref: 478cca14a59bb94403da17ea93fe3930dca4df2f
parent: ce33a312daca1944e61a11c4e7522d37f4da4f4d
author: Werner Lemberg <[email protected]>
date: Sun Dec 21 12:38:23 EST 2008

* src/base/ftpfr.c (FT_Get_PFR_Metrics): Protect against NULL
arguments.
Fix return value for non-PFR fonts.  Both problems reported by Chi
Nguyen <[email protected]>.

git/fs: mount .git/fs: mount/attach disallowed
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2008-12-21  Werner Lemberg  <[email protected]>
+
+	* src/base/ftpfr.c (FT_Get_PFR_Metrics): Protect against NULL
+	arguments.
+	Fix return value for non-PFR fonts.  Both problems reported by Chi
+	Nguyen <[email protected]>.
+
 2008-12-21  anonymous
 
 	FT_USE_MODULE declares things as:
--- a/include/freetype/ftpfr.h
+++ b/include/freetype/ftpfr.h
@@ -4,7 +4,7 @@
 /*                                                                         */
 /*    FreeType API for accessing PFR-specific data (specification only).   */
 /*                                                                         */
-/*  Copyright 2002, 2003, 2004, 2006 by                                    */
+/*  Copyright 2002, 2003, 2004, 2006, 2008 by                              */
 /*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
 /*                                                                         */
 /*  This file is part of the FreeType project, and may only be used,       */
@@ -73,11 +73,11 @@
   *      A 16.16 fixed-point number used to scale distance expressed
   *      in metrics units to device sub-pixels.  This is equivalent to
   *      `face->size->x_scale', but for metrics only.  Optional (parameter
-  *      can be NULL)
+  *      can be NULL).
   *
   *    ametrics_y_scale ::
   *      Same as `ametrics_x_scale' but for the vertical direction.
-  *      optional (parameter can be NULL)
+  *      optional (parameter can be NULL).
   *
   * @return:
   *    FreeType error code.  0~means success.
--- a/src/base/ftpfr.c
+++ b/src/base/ftpfr.c
@@ -4,7 +4,7 @@
 /*                                                                         */
 /*    FreeType API for accessing PFR-specific data (body).                 */
 /*                                                                         */
-/*  Copyright 2002, 2003, 2004 by                                          */
+/*  Copyright 2002, 2003, 2004, 2008 by                                    */
 /*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
 /*                                                                         */
 /*  This file is part of the FreeType project, and may only be used,       */
@@ -46,6 +46,9 @@
     FT_Service_PfrMetrics  service;
 
 
+    if ( !face )
+      return FT_Err_Invalid_Argument;
+
     service = ft_pfr_check( face );
     if ( service )
     {
@@ -55,15 +58,18 @@
                                     ametrics_x_scale,
                                     ametrics_y_scale );
     }
-    else if ( face )
+    else
     {
       FT_Fixed  x_scale, y_scale;
 
 
       /* this is not a PFR font */
-      *aoutline_resolution = face->units_per_EM;
-      *ametrics_resolution = face->units_per_EM;
+      if ( aoutline_resolution )
+        *aoutline_resolution = face->units_per_EM;
 
+      if ( ametrics_resolution )
+        *ametrics_resolution = face->units_per_EM;
+
       x_scale = y_scale = 0x10000L;
       if ( face->size )
       {
@@ -70,11 +76,15 @@
         x_scale = face->size->metrics.x_scale;
         y_scale = face->size->metrics.y_scale;
       }
-      *ametrics_x_scale = x_scale;
-      *ametrics_y_scale = y_scale;
+
+      if ( ametrics_x_scale )
+        *ametrics_x_scale = x_scale;
+
+      if ( ametrics_y_scale )
+        *ametrics_y_scale = y_scale;
+
+      error = FT_Err_Unknown_File_Format;
     }
-    else
-      error = FT_Err_Invalid_Argument;
 
     return error;
   }
@@ -92,14 +102,15 @@
     FT_Service_PfrMetrics  service;
 
 
+    if ( !face )
+      return FT_Err_Invalid_Argument;
+
     service = ft_pfr_check( face );
     if ( service )
       error = service->get_kerning( face, left, right, avector );
-    else if ( face )
+    else
       error = FT_Get_Kerning( face, left, right,
                               FT_KERNING_UNSCALED, avector );
-    else
-      error = FT_Err_Invalid_Argument;
 
     return error;
   }