shithub: freetype+ttf2subf

Download patch

ref: 52170ac0ce5b6c738e88a94d12bee0794474d7f4
parent: f7c6b11691261590933408c343283faa540be223
author: suzuki toshiya <[email protected]>
date: Fri Jul 31 20:32:11 EDT 2009

otvalid: Truncate the glyph index to 16-bit.

git/fs: mount .git/fs: mount/attach disallowed
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,14 @@
 2009-07-31  suzuki toshiya <[email protected]>
 
+	otvalid: Truncate the glyph index to 16-bit.
+
+	* src/otvalid/otvalid.c (otv_validate): Checks
+	face->num_glyphs does not exceed 16-bit limit,
+	pass FT_UInt num_glyphs to backend functions
+	otv_{GPOS|GSUB|GDEF|JSTF|MATH}_validate().
+
+2009-07-31  suzuki toshiya <[email protected]>
+
 	cache: Insert explict casts for LP64 systems.
 
 	* src/cache/ftcbasic.c (FTC_ImageCache_Lookup,
--- a/src/otvalid/otvmod.c
+++ b/src/otvalid/otvmod.c
@@ -82,6 +82,7 @@
     FT_Byte* volatile         math;
     FT_ULong                  len_base, len_gdef, len_gpos, len_gsub, len_jstf;
     FT_ULong                  len_math;
+    FT_UInt                   num_glyphs = (FT_UInt)face->num_glyphs;
     FT_ValidatorRec volatile  valid;
 
 
@@ -88,6 +89,18 @@
     base     = gdef     = gpos     = gsub     = jstf     = math     = NULL;
     len_base = len_gdef = len_gpos = len_gsub = len_jstf = len_math = 0;
 
+    /*
+     * XXX: OpenType tables cannot handle 32-bit glyph index,
+     *      although broken TrueType can have 32-bit glyph index.
+     */
+    if ( face->num_glyphs > 0xFFFFL )
+    {
+      FT_TRACE1(( "otv_validate: Invalid glyphs index (0x0000FFFF - 0x%08x) ",
+                  face->num_glyphs ));
+      FT_TRACE1(( "are not handled by OpenType tables\n" ));
+      num_glyphs = 0xFFFF;
+    }
+
     /* load tables */
 
     if ( ot_flags & FT_VALIDATE_BASE )
@@ -148,7 +161,7 @@
     {
       ft_validator_init( &valid, gpos, gpos + len_gpos, FT_VALIDATE_DEFAULT );
       if ( ft_setjmp( valid.jump_buffer ) == 0 )
-        otv_GPOS_validate( gpos, face->num_glyphs, &valid );
+        otv_GPOS_validate( gpos, num_glyphs, &valid );
       error = valid.error;
       if ( error )
         goto Exit;
@@ -158,7 +171,7 @@
     {
       ft_validator_init( &valid, gsub, gsub + len_gsub, FT_VALIDATE_DEFAULT );
       if ( ft_setjmp( valid.jump_buffer ) == 0 )
-        otv_GSUB_validate( gsub, face->num_glyphs, &valid );
+        otv_GSUB_validate( gsub, num_glyphs, &valid );
       error = valid.error;
       if ( error )
         goto Exit;
@@ -168,7 +181,7 @@
     {
       ft_validator_init( &valid, gdef, gdef + len_gdef, FT_VALIDATE_DEFAULT );
       if ( ft_setjmp( valid.jump_buffer ) == 0 )
-        otv_GDEF_validate( gdef, gsub, gpos, face->num_glyphs, &valid );
+        otv_GDEF_validate( gdef, gsub, gpos, num_glyphs, &valid );
       error = valid.error;
       if ( error )
         goto Exit;
@@ -178,7 +191,7 @@
     {
       ft_validator_init( &valid, jstf, jstf + len_jstf, FT_VALIDATE_DEFAULT );
       if ( ft_setjmp( valid.jump_buffer ) == 0 )
-        otv_JSTF_validate( jstf, gsub, gpos, face->num_glyphs, &valid );
+        otv_JSTF_validate( jstf, gsub, gpos, num_glyphs, &valid );
       error = valid.error;
       if ( error )
         goto Exit;
@@ -188,7 +201,7 @@
     {
       ft_validator_init( &valid, math, math + len_math, FT_VALIDATE_DEFAULT );
       if ( ft_setjmp( valid.jump_buffer ) == 0 )
-        otv_MATH_validate( math, face->num_glyphs, &valid );
+        otv_MATH_validate( math, num_glyphs, &valid );
       error = valid.error;
       if ( error )
         goto Exit;