Commit ac0f4454f7606af0b2284a5f3511432fd96b099d

suzuki toshiya 2013-09-25T10:57:17

[bdf, pcf] Refuse non-zero face_index. Suggested by Akira Tagoh, see http://lists.gnu.org/archive/html/freetype/2013-09/msg00030.html * src/bdf/bdfdrivr.c (BDF_Face_Init): Return Invalid_Argument error when the font could be opened but non-zero face_index is given. * src/pcf/pcfdrivr.c (PCF_Face_Init): Ditto. * src/type42/t42objs.c (T42_Face_Init): Remove unrequired FT_UNUSED macro for face_index because it is validated in later.

diff --git a/ChangeLog b/ChangeLog
index 55467c2..8e32d45 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2013-09-25  suzuki toshiya  <mpsuzuki@hiroshima-u.ac.jp>
+
+	[bdf, pcf] Refuse non-zero face_index.
+	Suggested by Akira Tagoh, see
+
+	  http://lists.gnu.org/archive/html/freetype/2013-09/msg00030.html
+
+	* src/bdf/bdfdrivr.c (BDF_Face_Init): Return Invalid_Argument error
+	when the font could be opened but non-zero face_index is given.
+	* src/pcf/pcfdrivr.c (PCF_Face_Init): Ditto.
+
+	* src/type42/t42objs.c (T42_Face_Init): Remove unrequired FT_UNUSED
+	macro for face_index because it is validated in later.
+
+
 2013-09-23  Werner Lemberg  <wl@gnu.org>
 
 	Fix Savannah bug #40090.
diff --git a/src/bdf/bdfdrivr.c b/src/bdf/bdfdrivr.c
index a0ddd28..caa142b 100644
--- a/src/bdf/bdfdrivr.c
+++ b/src/bdf/bdfdrivr.c
@@ -351,7 +351,6 @@ THE SOFTWARE.
 
     FT_UNUSED( num_params );
     FT_UNUSED( params );
-    FT_UNUSED( face_index );
 
 
     FT_TRACE2(( "BDF driver\n" ));
@@ -375,6 +374,19 @@ THE SOFTWARE.
 
     /* we have a bdf font: let's construct the face object */
     face->bdffont = font;
+
+    /* BDF could not have multiple face in single font file.
+     * XXX: non-zero face_index is already invalid argument, but
+     *      Type1, Type42 driver has a convention to return
+     *      an invalid argument error when the font could be
+     *      opened by the specified driver.
+     */
+    if ( face_index > 0 ) {
+      FT_ERROR(( "BDF_Face_Init: invalid face index\n" ));
+      BDF_Face_Done( bdfface );
+      return FT_THROW( Invalid_Argument );
+    }
+ 
     {
       bdf_property_t*  prop = NULL;
 
diff --git a/src/pcf/pcfdrivr.c b/src/pcf/pcfdrivr.c
index ac824bd..748cbca 100644
--- a/src/pcf/pcfdrivr.c
+++ b/src/pcf/pcfdrivr.c
@@ -267,7 +267,6 @@ THE SOFTWARE.
 
     FT_UNUSED( num_params );
     FT_UNUSED( params );
-    FT_UNUSED( face_index );
 
 
     FT_TRACE2(( "PCF driver\n" ));
@@ -346,6 +345,18 @@ THE SOFTWARE.
 #endif
     }
 
+    /* PCF could not have multiple face in single font file.
+     * XXX: non-zero face_index is already invalid argument, but
+     *      Type1, Type42 driver has a convention to return
+     *      an invalid argument error when the font could be
+     *      opened by the specified driver.
+     */
+    if ( face_index > 0 ) {
+      FT_ERROR(( "PCF_Face_Init: invalid face index\n" ));
+      PCF_Face_Done( pcfface );
+      return FT_THROW( Invalid_Argument );
+    }
+
     /* set up charmap */
     {
       FT_String  *charset_registry = face->charset_registry;
diff --git a/src/type42/t42objs.c b/src/type42/t42objs.c
index c1c3e08..f5aa2ca 100644
--- a/src/type42/t42objs.c
+++ b/src/type42/t42objs.c
@@ -171,7 +171,6 @@
 
     FT_UNUSED( num_params );
     FT_UNUSED( params );
-    FT_UNUSED( face_index );
     FT_UNUSED( stream );