ref: d81947e4294edebd8aa417366f690d0c03638fed
parent: 6f1eca046074c024a8c9235caa887b9cbadde5c1
author: Wu, Chia-I (吳佳一) <[email protected]>
date: Sun Nov 20 22:04:03 EST 2005
* 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.
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2005-11-21 Chia-I Wu <[email protected]>
+
+ * 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 <[email protected]>
* src/sfnt/ttload.c (sfnt_dir_check): Clean up and return correct
--- 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;
--- a/src/sfnt/ttload.c
+++ b/src/sfnt/ttload.c
@@ -134,14 +134,8 @@
}
- /* 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). */
+ /* Here, we: */
/* */
- /* 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: */
- /* */
/* - check that `num_tables' is valid */
/* - look for a "head" table, check its size, and parse it to */
/* see if its "magic" field is correctly set */
@@ -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;
}
@@ -427,6 +423,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;