From c880e814a50100577811a8a51bc06b4275c55a7e Mon Sep 17 00:00:00 2001 From: Eric Mader Date: Fri, 6 Sep 2002 22:45:23 +0000 Subject: [PATCH] Don't fail when reading an empty script. --- src/ftxopen.c | 36 +++++++++++++++++++++++++----------- src/ftxopen.h | 1 + 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/src/ftxopen.c b/src/ftxopen.c index 3101d6fd8..a072daf71 100644 --- a/src/ftxopen.c +++ b/src/ftxopen.c @@ -130,7 +130,7 @@ if ( s->LangSysCount == 0 && s->DefaultLangSys.FeatureCount == 0 ) { - error = TTO_Err_Invalid_SubTable; + error = TTO_Err_Empty_Script; goto Fail2; } @@ -205,7 +205,7 @@ FT_Error error; FT_Memory memory = stream->memory; - FT_UShort n, m, count; + FT_UShort n, script_count; FT_ULong cur_offset, new_offset, base_offset; TTO_ScriptRecord* sr; @@ -216,39 +216,53 @@ if ( ACCESS_Frame( 2L ) ) return error; - count = sl->ScriptCount = GET_UShort(); + script_count = GET_UShort(); FORGET_Frame(); sl->ScriptRecord = NULL; - if ( ALLOC_ARRAY( sl->ScriptRecord, count, TTO_ScriptRecord ) ) + if ( ALLOC_ARRAY( sl->ScriptRecord, script_count, TTO_ScriptRecord ) ) return error; sr = sl->ScriptRecord; - for ( n = 0; n < count; n++ ) + sl->ScriptCount= 0; + for ( n = 0; n < script_count; n++ ) { if ( ACCESS_Frame( 6L ) ) goto Fail; - sr[n].ScriptTag = GET_ULong(); + sr[sl->ScriptCount].ScriptTag = GET_ULong(); new_offset = GET_UShort() + base_offset; FORGET_Frame(); cur_offset = FILE_Pos(); - if ( FILE_Seek( new_offset ) || - ( error = Load_Script( &sr[n].Script, stream ) ) != TT_Err_Ok ) - goto Fail; + + if ( FILE_Seek( new_offset ) ) + goto Fail; + + error = Load_Script( &sr[sl->ScriptCount].Script, stream ); + if ( error == TT_Err_Ok ) + sl->ScriptCount += 1; + else if ( error != TTO_Err_Empty_Script ) + goto Fail; + (void)FILE_Seek( cur_offset ); } + if ( sl->ScriptCount == 0 ) + { + error = TTO_Err_Invalid_SubTable; + goto Fail; + } + return TT_Err_Ok; Fail: - for ( m = 0; m < n; m++ ) - Free_Script( &sr[m].Script, memory ); + for ( n = 0; n < sl->ScriptCount; n++ ) + Free_Script( &sr[n].Script, memory ); FREE( sl->ScriptRecord ); return error; diff --git a/src/ftxopen.h b/src/ftxopen.h index 28dff902e..052f25cc7 100644 --- a/src/ftxopen.h +++ b/src/ftxopen.h @@ -38,6 +38,7 @@ extern "C" { #define TTO_Err_Not_Covered 0x1002 #define TTO_Err_Too_Many_Nested_Contexts 0x1003 #define TTO_Err_No_MM_Interpreter 0x1004 +#define TTO_Err_Empty_Script 0x1005 /* Script list related structures */