sfnt: Ignore invalid GIDs in glyph name lookup.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
diff --git a/ChangeLog b/ChangeLog
index 0bbb95b..ec04930 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,16 @@
2009-07-31 suzuki toshiya <mpsuzuki@hiroshima-u.ac.jp>
+ sfnt: Ignore invalid GIDs in glyph name lookup.
+
+ * include/freetype/internal/fttrace.h:
+ New trace module for sfdriver.c is added.
+
+ * src/sfnt/sfdriver.c (sfnt_get_name_index):
+ Restrict glyph name lookup to FT_UInt GID.
+ Genuine TrueType can hold 16-bit glyphs.
+
+2009-07-31 suzuki toshiya <mpsuzuki@hiroshima-u.ac.jp>
+
pcf: Fix a comparison between FT_Long and FT_ULong.
* src/pcf/pcfread.c (pcf_get_bitmaps): Return an error
diff --git a/include/freetype/internal/fttrace.h b/include/freetype/internal/fttrace.h
index fa12f31..e9b383a 100644
--- a/include/freetype/internal/fttrace.h
+++ b/include/freetype/internal/fttrace.h
@@ -43,6 +43,7 @@ FT_TRACE_DEF( synth ) /* bold/slant synthesizer (ftsynth.c) */
FT_TRACE_DEF( cache ) /* cache sub-system (ftcache.c, etc.) */
/* SFNT driver components */
+FT_TRACE_DEF( sfdriver ) /* SFNT font driver (sfdriver.c) */
FT_TRACE_DEF( sfobjs ) /* SFNT object handler (sfobjs.c) */
FT_TRACE_DEF( ttcmap ) /* charmap handler (ttcmap.c) */
FT_TRACE_DEF( ttkern ) /* kerning handler (ttkern.c) */
diff --git a/src/sfnt/sfdriver.c b/src/sfnt/sfdriver.c
index 5429fde..8d7d5e5 100644
--- a/src/sfnt/sfdriver.c
+++ b/src/sfnt/sfdriver.c
@@ -49,6 +49,15 @@
#include FT_SERVICE_SFNT_H
#include FT_SERVICE_TT_CMAP_H
+ /*************************************************************************/
+ /* */
+ /* The macro FT_COMPONENT is used in trace mode. It is an implicit */
+ /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */
+ /* messages during execution. */
+ /* */
+#undef FT_COMPONENT
+#define FT_COMPONENT trace_sfdriver
+
/*
* SFNT TABLE SERVICE
@@ -157,11 +166,19 @@
sfnt_get_name_index( TT_Face face,
FT_String* glyph_name )
{
- FT_Face root = &face->root;
- FT_Long i;
+ FT_Face root = &face->root;
+ FT_UInt i, max_gid = FT_UINT_MAX;
+
+ if ( root->num_glyphs < 0 )
+ return 0;
+ else if ( ( FT_ULong ) root->num_glyphs < FT_UINT_MAX )
+ max_gid = ( FT_UInt ) root->num_glyphs;
+ else
+ FT_TRACE0(( "Ignore glyph names for invalid GID 0x%08x - 0x%08x\n",
+ FT_UINT_MAX, root->num_glyphs ));
- for ( i = 0; i < root->num_glyphs; i++ )
+ for ( i = 0; i < max_gid; i++ )
{
FT_String* gname;
FT_Error error = tt_face_get_ps_name( face, i, &gname );
@@ -171,7 +188,7 @@
continue;
if ( !ft_strcmp( glyph_name, gname ) )
- return (FT_UInt)i;
+ return i;
}
return 0;