From d81947e4294edebd8aa417366f690d0c03638fed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wu=2C=20Chia-I=20=28=E5=90=B3=E4=BD=B3=E4=B8=80=29?= Date: Mon, 21 Nov 2005 03:04:03 +0000 Subject: [PATCH] * src/sfnt/sfobjs.c (sfnt_init_face): Check that format_tag is known before loading the table directory. * src/sfnt/ttload.c (tt_face_load_sfnt_header, tt_face_load_directory): Delay sfnt_dir_check from tt_face_load_sfnt_header to tt_face_load_directory. --- ChangeLog | 9 +++++++++ src/sfnt/sfobjs.c | 7 +++++++ src/sfnt/ttload.c | 26 +++++++++++++++----------- 3 files changed, 31 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index f731573f7..7a4b984c0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2005-11-21 Chia-I Wu + + * src/sfnt/sfobjs.c (sfnt_init_face): Check that format_tag is known + before loading the table directory. + + * src/sfnt/ttload.c (tt_face_load_sfnt_header, + tt_face_load_directory): Delay sfnt_dir_check from + tt_face_load_sfnt_header to tt_face_load_directory. + 2005-11-20 Chia-I Wu * src/sfnt/ttload.c (sfnt_dir_check): Clean up and return correct diff --git a/src/sfnt/sfobjs.c b/src/sfnt/sfobjs.c index 991705dc8..4fa6d7174 100644 --- a/src/sfnt/sfobjs.c +++ b/src/sfnt/sfobjs.c @@ -376,6 +376,13 @@ if ( error ) goto Exit; + if ( sfnt_header.format_tag != 0x00010000UL && + sfnt_header.format_tag != TTAG_ttcf && + sfnt_header.format_tag != FT_MAKE_TAG( 'O', 'T', 'T', 'O' ) && + sfnt_header.format_tag != TTAG_true && + sfnt_header.format_tag != 0x00020000UL ) + return SFNT_Err_Unknown_File_Format; + face->format_tag = sfnt_header.format_tag; face->num_tables = sfnt_header.num_tables; diff --git a/src/sfnt/ttload.c b/src/sfnt/ttload.c index 6a9a7a29f..77acfc250 100644 --- a/src/sfnt/ttload.c +++ b/src/sfnt/ttload.c @@ -134,13 +134,7 @@ } - /* In theory, we should check the values of `search_range', */ - /* `entry_selector', and `range_shift' to detect non-SFNT based files */ - /* whose header might also start with 0x100000L (yes, these exist). */ - /* */ - /* Very unfortunately, many TrueType fonts don't have these fields */ - /* set correctly and we must ignore them to support them. An */ - /* alternative way to check the font file is thus to: */ + /* Here, we: */ /* */ /* - check that `num_tables' is valid */ /* - look for a "head" table, check its size, and parse it to */ @@ -381,10 +375,12 @@ FT_STREAM_READ_FIELDS( sfnt_header_fields, sfnt ) ) return error; - /* now check the sfnt directory */ - error = sfnt_dir_check( sfnt, stream ); - if ( error ) - FT_TRACE2(( "tt_face_load_sfnt_header: invalid SFNT!\n" )); + /* many fonts don't have these fields set correctly */ +#if 0 + if ( sfnt->search_range != 1 << ( sfnt->entry_selector + 4 ) || + sfnt->search_range + sfnt->range_shift != sfnt->num_tables << 4 ) + return SFNT_Err_Unknown_File_Format; +#endif return error; } @@ -428,6 +424,14 @@ FT_TRACE2(( "-- Tables count: %12u\n", sfnt->num_tables )); FT_TRACE2(( "-- Format version: %08lx\n", sfnt->format_tag )); + /* check first */ + error = sfnt_dir_check( sfnt, stream ); + if ( error ) { + FT_TRACE2(( "tt_face_load_directory: directory checking failed!\n" )); + + return error; + } + face->num_tables = sfnt->num_tables; if ( FT_QNEW_ARRAY( face->dir_tables, face->num_tables ) )