From 2eaf0cf8fd6e7c290497fedb08134a89e7b49b1d Mon Sep 17 00:00:00 2001 From: Konstantin Ritt Date: Thu, 19 Mar 2015 17:34:42 +0400 Subject: Update bundled FreeType to 2.5.5 Removed everything, imported with help of import_from_tarball.sh script, and then added a pre-generated builds/unix/ftconfig.h Task-number: QTBUG-44648 Change-Id: Iea948e41f7761f1580382b3763d04c7a61383382 Reviewed-by: Lars Knoll --- src/3rdparty/freetype/src/type42/t42drivr.c | 62 ++++++----- src/3rdparty/freetype/src/type42/t42drivr.h | 2 +- src/3rdparty/freetype/src/type42/t42error.h | 3 +- src/3rdparty/freetype/src/type42/t42objs.c | 135 +++++++++++++++-------- src/3rdparty/freetype/src/type42/t42objs.h | 22 ++-- src/3rdparty/freetype/src/type42/t42parse.c | 159 ++++++++++++++++++---------- 6 files changed, 239 insertions(+), 144 deletions(-) (limited to 'src/3rdparty/freetype/src/type42') diff --git a/src/3rdparty/freetype/src/type42/t42drivr.c b/src/3rdparty/freetype/src/type42/t42drivr.c index 820c679612..3ad1bde79f 100644 --- a/src/3rdparty/freetype/src/type42/t42drivr.c +++ b/src/3rdparty/freetype/src/type42/t42drivr.c @@ -4,7 +4,8 @@ /* */ /* High-level Type 42 driver interface (body). */ /* */ -/* Copyright 2002, 2003, 2004, 2006, 2007, 2009 by Roberto Alameda. */ +/* Copyright 2002-2004, 2006, 2007, 2009, 2011, 2013 by */ +/* Roberto Alameda. */ /* */ /* This file is part of the FreeType project, and may only be used, */ /* modified, and distributed under the terms of the FreeType project */ @@ -63,7 +64,7 @@ { FT_STRCPYN( buffer, face->type1.glyph_names[glyph_index], buffer_max ); - return T42_Err_Ok; + return FT_Err_Ok; } @@ -71,13 +72,13 @@ t42_get_name_index( T42_Face face, FT_String* glyph_name ) { - FT_Int i; - FT_String* gname; + FT_Int i; for ( i = 0; i < face->type1.num_glyphs; i++ ) { - gname = face->type1.glyph_names[i]; + FT_String* gname = face->type1.glyph_names[i]; + if ( glyph_name[0] == gname[0] && !ft_strcmp( glyph_name, gname ) ) return (FT_UInt)ft_atol( (const char *)face->type1.charstrings[i] ); @@ -125,7 +126,7 @@ { *afont_info = ((T42_Face)face)->type1.font_info; - return T42_Err_Ok; + return FT_Err_Ok; } @@ -135,7 +136,7 @@ { *afont_extra = ((T42_Face)face)->type1.font_extra; - return T42_Err_Ok; + return FT_Err_Ok; } @@ -154,16 +155,17 @@ { *afont_private = ((T42_Face)face)->type1.private_dict; - return T42_Err_Ok; + return FT_Err_Ok; } static const FT_Service_PsInfoRec t42_service_ps_info = { (PS_GetFontInfoFunc) t42_ps_get_font_info, - (PS_GetFontExtraFunc) t42_ps_get_font_extra, + (PS_GetFontExtraFunc) t42_ps_get_font_extra, (PS_HasGlyphNamesFunc) t42_ps_has_glyph_names, - (PS_GetFontPrivateFunc)t42_ps_get_font_private + (PS_GetFontPrivateFunc)t42_ps_get_font_private, + (PS_GetFontValueFunc) NULL /* not implemented */ }; @@ -183,11 +185,11 @@ }; - static FT_Module_Interface - T42_Get_Interface( FT_Driver driver, + FT_CALLBACK_DEF( FT_Module_Interface ) + T42_Get_Interface( FT_Module module, const FT_String* t42_interface ) { - FT_UNUSED( driver ); + FT_UNUSED( module ); return ft_service_list_lookup( t42_services, t42_interface ); } @@ -212,34 +214,30 @@ 0, /* format interface */ - (FT_Module_Constructor)T42_Driver_Init, - (FT_Module_Destructor) T42_Driver_Done, - (FT_Module_Requester) T42_Get_Interface, + T42_Driver_Init, + T42_Driver_Done, + T42_Get_Interface, }, sizeof ( T42_FaceRec ), sizeof ( T42_SizeRec ), sizeof ( T42_GlyphSlotRec ), - (FT_Face_InitFunc) T42_Face_Init, - (FT_Face_DoneFunc) T42_Face_Done, - (FT_Size_InitFunc) T42_Size_Init, - (FT_Size_DoneFunc) T42_Size_Done, - (FT_Slot_InitFunc) T42_GlyphSlot_Init, - (FT_Slot_DoneFunc) T42_GlyphSlot_Done, + T42_Face_Init, + T42_Face_Done, + T42_Size_Init, + T42_Size_Done, + T42_GlyphSlot_Init, + T42_GlyphSlot_Done, -#ifdef FT_CONFIG_OPTION_OLD_INTERNALS - ft_stub_set_char_sizes, - ft_stub_set_pixel_sizes, -#endif - (FT_Slot_LoadFunc) T42_GlyphSlot_Load, + T42_GlyphSlot_Load, - (FT_Face_GetKerningFunc) 0, - (FT_Face_AttachFunc) 0, + 0, /* FT_Face_GetKerningFunc */ + 0, /* FT_Face_AttachFunc */ - (FT_Face_GetAdvancesFunc) 0, - (FT_Size_RequestFunc) T42_Size_Request, - (FT_Size_SelectFunc) T42_Size_Select + 0, /* FT_Face_GetAdvancesFunc */ + T42_Size_Request, + T42_Size_Select }; diff --git a/src/3rdparty/freetype/src/type42/t42drivr.h b/src/3rdparty/freetype/src/type42/t42drivr.h index 4717e4613f..9a1e97e30e 100644 --- a/src/3rdparty/freetype/src/type42/t42drivr.h +++ b/src/3rdparty/freetype/src/type42/t42drivr.h @@ -27,7 +27,7 @@ FT_BEGIN_HEADER #ifdef FT_CONFIG_OPTION_PIC #error "this module does not support PIC yet" -#endif +#endif FT_EXPORT_VAR( const FT_Driver_ClassRec ) t42_driver_class; diff --git a/src/3rdparty/freetype/src/type42/t42error.h b/src/3rdparty/freetype/src/type42/t42error.h index b230910012..217ae8bd52 100644 --- a/src/3rdparty/freetype/src/type42/t42error.h +++ b/src/3rdparty/freetype/src/type42/t42error.h @@ -4,7 +4,7 @@ /* */ /* Type 42 error codes (specification only). */ /* */ -/* Copyright 2002, 2003 by */ +/* Copyright 2002, 2003, 2012 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -29,6 +29,7 @@ #undef __FTERRORS_H__ +#undef FT_ERR_PREFIX #define FT_ERR_PREFIX T42_Err_ #define FT_ERR_BASE FT_Mod_Err_Type42 diff --git a/src/3rdparty/freetype/src/type42/t42objs.c b/src/3rdparty/freetype/src/type42/t42objs.c index 9081ffc6d2..915e81fe74 100644 --- a/src/3rdparty/freetype/src/type42/t42objs.c +++ b/src/3rdparty/freetype/src/type42/t42objs.c @@ -4,7 +4,7 @@ /* */ /* Type 42 objects manager (body). */ /* */ -/* Copyright 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 */ +/* Copyright 2002-2009, 2011, 2013 */ /* by Roberto Alameda. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -21,6 +21,7 @@ #include "t42error.h" #include FT_INTERNAL_DEBUG_H #include FT_LIST_H +#include FT_TRUETYPE_IDS_H #undef FT_COMPONENT @@ -46,6 +47,12 @@ if ( FT_ALLOC( face->ttf_data, 12 ) ) goto Exit; + /* while parsing the font we always update `face->ttf_size' so that */ + /* even in case of buggy data (which might lead to premature end of */ + /* scanning without causing an error) the call to `FT_Open_Face' in */ + /* `T42_Face_Init' passes the correct size */ + face->ttf_size = 12; + error = t42_parser_init( parser, face->root.stream, memory, @@ -60,7 +67,9 @@ if ( type1->font_type != 42 ) { - error = T42_Err_Unknown_File_Format; + FT_ERROR(( "T42_Open_Face: cannot handle FontType %d\n", + type1->font_type )); + error = FT_THROW( Unknown_File_Format ); goto Exit; } @@ -71,7 +80,7 @@ if ( !loader.charstrings.init ) { FT_ERROR(( "T42_Open_Face: no charstrings array in face\n" )); - error = T42_Err_Invalid_File_Format; + error = FT_THROW( Invalid_File_Format ); } loader.charstrings.init = 0; @@ -90,7 +99,6 @@ if ( type1->encoding_type == T1_ENCODING_TYPE_ARRAY ) { FT_Int charcode, idx, min_char, max_char; - FT_Byte* char_name; FT_Byte* glyph_name; @@ -106,6 +114,9 @@ charcode = 0; for ( ; charcode < loader.encoding_table.max_elems; charcode++ ) { + FT_Byte* char_name; + + type1->encoding.char_index[charcode] = 0; type1->encoding.char_name [charcode] = (char *)".notdef"; @@ -151,11 +162,12 @@ FT_LOCAL_DEF( FT_Error ) T42_Face_Init( FT_Stream stream, - T42_Face face, + FT_Face t42face, /* T42_Face */ FT_Int face_index, FT_Int num_params, FT_Parameter* params ) { + T42_Face face = (T42_Face)t42face; FT_Error error; FT_Service_PsCMaps psnames; PSAux_Service psaux; @@ -165,7 +177,6 @@ FT_UNUSED( num_params ); FT_UNUSED( params ); - FT_UNUSED( face_index ); FT_UNUSED( stream ); @@ -178,6 +189,14 @@ face->psaux = FT_Get_Module_Interface( FT_FACE_LIBRARY( face ), "psaux" ); psaux = (PSAux_Service)face->psaux; + if ( !psaux ) + { + FT_ERROR(( "T42_Face_Init: cannot access `psaux' module\n" )); + error = FT_THROW( Missing_Module ); + goto Exit; + } + + FT_TRACE2(( "Type 42 driver\n" )); /* open the tokenizer, this will also check the font format */ error = T42_Open_Face( face ); @@ -192,7 +211,7 @@ if ( face_index > 0 ) { FT_ERROR(( "T42_Face_Init: invalid face index\n" )); - error = T42_Err_Invalid_Argument; + error = FT_THROW( Invalid_Argument ); goto Exit; } @@ -205,9 +224,9 @@ root->num_charmaps = 0; root->face_index = 0; - root->face_flags = FT_FACE_FLAG_SCALABLE | - FT_FACE_FLAG_HORIZONTAL | - FT_FACE_FLAG_GLYPH_NAMES; + root->face_flags |= FT_FACE_FLAG_SCALABLE | + FT_FACE_FLAG_HORIZONTAL | + FT_FACE_FLAG_GLYPH_NAMES; if ( info->is_fixed_pitch ) root->face_flags |= FT_FACE_FLAG_FIXED_WIDTH; @@ -273,7 +292,9 @@ FT_Open_Args args; - args.flags = FT_OPEN_MEMORY; + args.flags = FT_OPEN_MEMORY | FT_OPEN_DRIVER; + args.driver = FT_Get_Module( FT_FACE_LIBRARY( face ), + "truetype" ); args.memory_base = face->ttf_data; args.memory_size = face->ttf_size; @@ -320,7 +341,7 @@ root->face_flags |= FT_FACE_FLAG_VERTICAL; { - if ( psnames && psaux ) + if ( psnames ) { FT_CharMapRec charmap; T1_CMap_Classes cmap_classes = psaux->t1_cmap_classes; @@ -330,39 +351,43 @@ charmap.face = root; /* first of all, try to synthesize a Unicode charmap */ - charmap.platform_id = 3; - charmap.encoding_id = 1; + charmap.platform_id = TT_PLATFORM_MICROSOFT; + charmap.encoding_id = TT_MS_ID_UNICODE_CS; charmap.encoding = FT_ENCODING_UNICODE; - FT_CMap_New( cmap_classes->unicode, NULL, &charmap, NULL ); + error = FT_CMap_New( cmap_classes->unicode, NULL, &charmap, NULL ); + if ( error && + FT_ERR_NEQ( error, No_Unicode_Glyph_Name ) ) + goto Exit; + error = FT_Err_Ok; /* now, generate an Adobe Standard encoding when appropriate */ - charmap.platform_id = 7; + charmap.platform_id = TT_PLATFORM_ADOBE; clazz = NULL; switch ( type1->encoding_type ) { case T1_ENCODING_TYPE_STANDARD: charmap.encoding = FT_ENCODING_ADOBE_STANDARD; - charmap.encoding_id = 0; + charmap.encoding_id = TT_ADOBE_ID_STANDARD; clazz = cmap_classes->standard; break; case T1_ENCODING_TYPE_EXPERT: charmap.encoding = FT_ENCODING_ADOBE_EXPERT; - charmap.encoding_id = 1; + charmap.encoding_id = TT_ADOBE_ID_EXPERT; clazz = cmap_classes->expert; break; case T1_ENCODING_TYPE_ARRAY: charmap.encoding = FT_ENCODING_ADOBE_CUSTOM; - charmap.encoding_id = 2; + charmap.encoding_id = TT_ADOBE_ID_CUSTOM; clazz = cmap_classes->custom; break; case T1_ENCODING_TYPE_ISOLATIN1: charmap.encoding = FT_ENCODING_ADOBE_LATIN_1; - charmap.encoding_id = 3; + charmap.encoding_id = TT_ADOBE_ID_LATIN_1; clazz = cmap_classes->unicode; break; @@ -371,7 +396,7 @@ } if ( clazz ) - FT_CMap_New( clazz, NULL, &charmap, NULL ); + error = FT_CMap_New( clazz, NULL, &charmap, NULL ); #if 0 /* Select default charmap */ @@ -386,8 +411,9 @@ FT_LOCAL_DEF( void ) - T42_Face_Done( T42_Face face ) + T42_Face_Done( FT_Face t42face ) { + T42_Face face = (T42_Face)t42face; T1_Font type1; PS_FontInfo info; FT_Memory memory; @@ -455,36 +481,44 @@ /* FreeType error code. 0 means success. */ /* */ FT_LOCAL_DEF( FT_Error ) - T42_Driver_Init( T42_Driver driver ) + T42_Driver_Init( FT_Module module ) /* T42_Driver */ { - FT_Module ttmodule; + T42_Driver driver = (T42_Driver)module; + FT_Module ttmodule; - ttmodule = FT_Get_Module( FT_MODULE(driver)->library, "truetype" ); + ttmodule = FT_Get_Module( module->library, "truetype" ); + if ( !ttmodule ) + { + FT_ERROR(( "T42_Driver_Init: cannot access `truetype' module\n" )); + return FT_THROW( Missing_Module ); + } + driver->ttclazz = (FT_Driver_Class)ttmodule->clazz; - return T42_Err_Ok; + return FT_Err_Ok; } FT_LOCAL_DEF( void ) - T42_Driver_Done( T42_Driver driver ) + T42_Driver_Done( FT_Module module ) { - FT_UNUSED( driver ); + FT_UNUSED( module ); } FT_LOCAL_DEF( FT_Error ) - T42_Size_Init( T42_Size size ) + T42_Size_Init( FT_Size size ) /* T42_Size */ { - FT_Face face = size->root.face; + T42_Size t42size = (T42_Size)size; + FT_Face face = size->face; T42_Face t42face = (T42_Face)face; FT_Size ttsize; - FT_Error error = T42_Err_Ok; + FT_Error error; error = FT_New_Size( t42face->ttf_face, &ttsize ); - size->ttsize = ttsize; + t42size->ttsize = ttsize; FT_Activate_Size( ttsize ); @@ -493,10 +527,11 @@ FT_LOCAL_DEF( FT_Error ) - T42_Size_Request( T42_Size size, + T42_Size_Request( FT_Size t42size, /* T42_Size */ FT_Size_Request req ) { - T42_Face face = (T42_Face)size->root.face; + T42_Size size = (T42_Size)t42size; + T42_Face face = (T42_Face)t42size->face; FT_Error error; @@ -504,17 +539,18 @@ error = FT_Request_Size( face->ttf_face, req ); if ( !error ) - ( (FT_Size)size )->metrics = face->ttf_face->size->metrics; + t42size->metrics = face->ttf_face->size->metrics; return error; } FT_LOCAL_DEF( FT_Error ) - T42_Size_Select( T42_Size size, + T42_Size_Select( FT_Size t42size, /* T42_Size */ FT_ULong strike_index ) { - T42_Face face = (T42_Face)size->root.face; + T42_Size size = (T42_Size)t42size; + T42_Face face = (T42_Face)t42size->face; FT_Error error; @@ -522,7 +558,7 @@ error = FT_Select_Size( face->ttf_face, (FT_Int)strike_index ); if ( !error ) - ( (FT_Size)size )->metrics = face->ttf_face->size->metrics; + t42size->metrics = face->ttf_face->size->metrics; return error; @@ -530,9 +566,10 @@ FT_LOCAL_DEF( void ) - T42_Size_Done( T42_Size size ) + T42_Size_Done( FT_Size t42size ) /* T42_Size */ { - FT_Face face = size->root.face; + T42_Size size = (T42_Size)t42size; + FT_Face face = t42size->face; T42_Face t42face = (T42_Face)face; FT_ListNode node; @@ -547,12 +584,13 @@ FT_LOCAL_DEF( FT_Error ) - T42_GlyphSlot_Init( T42_GlyphSlot slot ) + T42_GlyphSlot_Init( FT_GlyphSlot t42slot ) /* T42_GlyphSlot */ { - FT_Face face = slot->root.face; - T42_Face t42face = (T42_Face)face; - FT_GlyphSlot ttslot; - FT_Error error = T42_Err_Ok; + T42_GlyphSlot slot = (T42_GlyphSlot)t42slot; + FT_Face face = t42slot->face; + T42_Face t42face = (T42_Face)face; + FT_GlyphSlot ttslot; + FT_Error error = FT_Err_Ok; if ( face->glyph == NULL ) @@ -571,8 +609,11 @@ FT_LOCAL_DEF( void ) - T42_GlyphSlot_Done( T42_GlyphSlot slot ) + T42_GlyphSlot_Done( FT_GlyphSlot t42slot ) /* T42_GlyphSlot */ { + T42_GlyphSlot slot = (T42_GlyphSlot)t42slot; + + FT_Done_GlyphSlot( slot->ttslot ); } @@ -614,6 +655,8 @@ FT_Driver_Class ttclazz = ((T42_Driver)glyph->face->driver)->ttclazz; + FT_TRACE1(( "T42_GlyphSlot_Load: glyph index %d\n", glyph_index )); + t42_glyphslot_clear( t42slot->ttslot ); error = ttclazz->load_glyph( t42slot->ttslot, t42size->ttsize, diff --git a/src/3rdparty/freetype/src/type42/t42objs.h b/src/3rdparty/freetype/src/type42/t42objs.h index 289dedcc69..02d13259be 100644 --- a/src/3rdparty/freetype/src/type42/t42objs.h +++ b/src/3rdparty/freetype/src/type42/t42objs.h @@ -4,7 +4,7 @@ /* */ /* Type 42 objects manager (specification). */ /* */ -/* Copyright 2002, 2003, 2006, 2007 by Roberto Alameda. */ +/* Copyright 2002, 2003, 2006, 2007, 2011 by Roberto Alameda. */ /* */ /* This file is part of the FreeType project, and may only be used, */ /* modified, and distributed under the terms of the FreeType project */ @@ -65,36 +65,36 @@ FT_BEGIN_HEADER FT_LOCAL( FT_Error ) T42_Face_Init( FT_Stream stream, - T42_Face face, + FT_Face face, FT_Int face_index, FT_Int num_params, FT_Parameter* params ); FT_LOCAL( void ) - T42_Face_Done( T42_Face face ); + T42_Face_Done( FT_Face face ); FT_LOCAL( FT_Error ) - T42_Size_Init( T42_Size size ); + T42_Size_Init( FT_Size size ); FT_LOCAL( FT_Error ) - T42_Size_Request( T42_Size size, + T42_Size_Request( FT_Size size, FT_Size_Request req ); FT_LOCAL( FT_Error ) - T42_Size_Select( T42_Size size, + T42_Size_Select( FT_Size size, FT_ULong strike_index ); FT_LOCAL( void ) - T42_Size_Done( T42_Size size ); + T42_Size_Done( FT_Size size ); FT_LOCAL( FT_Error ) - T42_GlyphSlot_Init( T42_GlyphSlot slot ); + T42_GlyphSlot_Init( FT_GlyphSlot slot ); FT_LOCAL( FT_Error ) @@ -104,14 +104,14 @@ FT_BEGIN_HEADER FT_Int32 load_flags ); FT_LOCAL( void ) - T42_GlyphSlot_Done( T42_GlyphSlot slot ); + T42_GlyphSlot_Done( FT_GlyphSlot slot ); FT_LOCAL( FT_Error ) - T42_Driver_Init( T42_Driver driver ); + T42_Driver_Init( FT_Module module ); FT_LOCAL( void ) - T42_Driver_Done( T42_Driver driver ); + T42_Driver_Done( FT_Module module ); /* */ diff --git a/src/3rdparty/freetype/src/type42/t42parse.c b/src/3rdparty/freetype/src/type42/t42parse.c index 13bda64c83..50708537df 100644 --- a/src/3rdparty/freetype/src/type42/t42parse.c +++ b/src/3rdparty/freetype/src/type42/t42parse.c @@ -4,7 +4,7 @@ /* */ /* Type 42 font parser (body). */ /* */ -/* Copyright 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 by */ +/* Copyright 2002-2014 by */ /* Roberto Alameda. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -52,7 +52,8 @@ /* as Type42 fonts have no Private dict, */ /* we set the last argument of T1_FIELD_XXX to 0 */ static const - T1_FieldRec t42_keywords[] = { + T1_FieldRec t42_keywords[] = + { #undef FT_STRUCTURE #define FT_STRUCTURE T1_FontInfo @@ -143,7 +144,7 @@ FT_Memory memory, PSAux_Service psaux ) { - FT_Error error = T42_Err_Ok; + FT_Error error = FT_Err_Ok; FT_Long size; @@ -174,8 +175,8 @@ if ( ft_memcmp( stream->cursor, "%!PS-TrueTypeFont", 17 ) != 0 ) { - FT_TRACE2(( "not a Type42 font\n" )); - error = T42_Err_Unknown_File_Format; + FT_TRACE2(( " not a Type42 font\n" )); + error = FT_THROW( Unknown_File_Format ); } FT_FRAME_EXIT(); @@ -254,27 +255,41 @@ FT_Face root = (FT_Face)&face->root; FT_Fixed temp[6]; FT_Fixed temp_scale; + FT_Int result; + + result = T1_ToFixedArray( parser, 6, temp, 3 ); - (void)T1_ToFixedArray( parser, 6, temp, 3 ); + if ( result < 6 ) + { + parser->root.error = FT_THROW( Invalid_File_Format ); + return; + } temp_scale = FT_ABS( temp[3] ); + if ( temp_scale == 0 ) + { + FT_ERROR(( "t1_parse_font_matrix: invalid font matrix\n" )); + parser->root.error = FT_THROW( Invalid_File_Format ); + return; + } + /* Set Units per EM based on FontMatrix values. We set the value to */ /* 1000 / temp_scale, because temp_scale was already multiplied by */ /* 1000 (in t1_tofixed, from psobjs.c). */ - root->units_per_EM = (FT_UShort)( FT_DivFix( 1000 * 0x10000L, - temp_scale ) >> 16 ); + root->units_per_EM = (FT_UShort)FT_DivFix( 1000, temp_scale ); /* we need to scale the values by 1.0/temp_scale */ - if ( temp_scale != 0x10000L ) { + if ( temp_scale != 0x10000L ) + { temp[0] = FT_DivFix( temp[0], temp_scale ); temp[1] = FT_DivFix( temp[1], temp_scale ); temp[2] = FT_DivFix( temp[2], temp_scale ); temp[4] = FT_DivFix( temp[4], temp_scale ); temp[5] = FT_DivFix( temp[5], temp_scale ); - temp[3] = 0x10000L; + temp[3] = temp[3] < 0 ? -0x10000L : 0x10000L; } matrix->xx = temp[0]; @@ -304,7 +319,7 @@ if ( cur >= limit ) { FT_ERROR(( "t42_parse_encoding: out of bounds\n" )); - parser->root.error = T42_Err_Invalid_File_Format; + parser->root.error = FT_THROW( Invalid_File_Format ); return; } @@ -313,7 +328,7 @@ if ( ft_isdigit( *cur ) || *cur == '[' ) { T1_Encoding encode = &face->type1.encoding; - FT_UInt count, n; + FT_Int count, n; PS_Table char_table = &loader->encoding_table; FT_Memory memory = parser->root.memory; FT_Error error; @@ -328,7 +343,7 @@ parser->root.cursor++; } else - count = (FT_UInt)T1_ToInt( parser ); + count = (FT_Int)T1_ToInt( parser ); T1_Skip_Spaces( parser ); if ( parser->root.cursor >= limit ) @@ -351,7 +366,7 @@ char* notdef = (char *)".notdef"; - T1_Add_Table( char_table, n, notdef, 8 ); + (void)T1_Add_Table( char_table, n, notdef, 8 ); } /* Now we need to read records of the form */ @@ -416,7 +431,7 @@ cur = parser->root.cursor; - if ( *cur == '/' && cur + 2 < limit && n < count ) + if ( cur + 2 < limit && *cur == '/' && n < count ) { FT_PtrDist len; @@ -425,6 +440,8 @@ parser->root.cursor = cur; T1_Skip_PS_Token( parser ); + if ( parser->root.cursor >= limit ) + return; if ( parser->root.error ) return; @@ -438,6 +455,19 @@ n++; } + else if ( only_immediates ) + { + /* Since the current position is not updated for */ + /* immediates-only mode we would get an infinite loop if */ + /* we don't do anything here. */ + /* */ + /* This encoding array is not valid according to the type1 */ + /* specification (it might be an encoding for a CID type1 */ + /* font, however), so we conclude that this font is NOT a */ + /* type1 font. */ + parser->root.error = FT_THROW( Unknown_File_Format ); + return; + } } else { @@ -449,8 +479,8 @@ T1_Skip_Spaces( parser ); } - face->type1.encoding_type = T1_ENCODING_TYPE_ARRAY; - parser->root.cursor = cur; + face->type1.encoding_type = T1_ENCODING_TYPE_ARRAY; + parser->root.cursor = cur; } /* Otherwise, we should have either `StandardEncoding', */ @@ -470,10 +500,7 @@ face->type1.encoding_type = T1_ENCODING_TYPE_ISOLATIN1; else - { - FT_ERROR(( "t42_parse_encoding: invalid token\n" )); - parser->root.error = T42_Err_Invalid_File_Format; - } + parser->root.error = FT_THROW( Ignore ); } } @@ -497,7 +524,7 @@ FT_Byte* limit = parser->root.limit; FT_Error error; FT_Int num_tables = 0; - FT_ULong count, ttf_size = 0; + FT_ULong count; FT_Long n, string_size, old_string_size, real_size; FT_Byte* string_buf = NULL; @@ -525,7 +552,7 @@ if ( parser->root.cursor >= limit || *parser->root.cursor++ != '[' ) { FT_ERROR(( "t42_parse_sfnts: can't find begin of sfnts vector\n" )); - error = T42_Err_Invalid_File_Format; + error = FT_THROW( Invalid_File_Format ); goto Fail; } @@ -553,6 +580,12 @@ /* don't include delimiters */ string_size = (FT_Long)( ( parser->root.cursor - cur - 2 + 1 ) / 2 ); + if ( !string_size ) + { + FT_ERROR(( "t42_parse_sfnts: invalid data in sfnts array\n" )); + error = FT_THROW( Invalid_File_Format ); + goto Fail; + } if ( FT_REALLOC( string_buf, old_string_size, string_size ) ) goto Fail; @@ -570,11 +603,17 @@ { FT_ERROR(( "t42_parse_sfnts: " "can't handle mixed binary and hex strings\n" )); - error = T42_Err_Invalid_File_Format; + error = FT_THROW( Invalid_File_Format ); goto Fail; } string_size = T1_ToInt( parser ); + if ( string_size < 0 ) + { + FT_ERROR(( "t42_parse_sfnts: invalid string size\n" )); + error = FT_THROW( Invalid_File_Format ); + goto Fail; + } T1_Skip_PS_Token( parser ); /* `RD' */ if ( parser->root.error ) @@ -582,30 +621,32 @@ string_buf = parser->root.cursor + 1; /* one space after `RD' */ - parser->root.cursor += string_size + 1; - if ( parser->root.cursor >= limit ) + if ( limit - parser->root.cursor < string_size ) { - FT_ERROR(( "t42_parse_sfnts: too many binary data\n" )); - error = T42_Err_Invalid_File_Format; + FT_ERROR(( "t42_parse_sfnts: too much binary data\n" )); + error = FT_THROW( Invalid_File_Format ); goto Fail; } + else + parser->root.cursor += string_size + 1; } if ( !string_buf ) { FT_ERROR(( "t42_parse_sfnts: invalid data in sfnts array\n" )); - error = T42_Err_Invalid_File_Format; + error = FT_THROW( Invalid_File_Format ); goto Fail; } - /* A string can have a trailing zero byte for padding. Ignore it. */ - if ( string_buf[string_size - 1] == 0 && ( string_size % 2 == 1 ) ) + /* A string can have a trailing zero (odd) byte for padding. */ + /* Ignore it. */ + if ( ( string_size & 1 ) && string_buf[string_size - 1] == 0 ) string_size--; if ( !string_size ) { FT_ERROR(( "t42_parse_sfnts: invalid string\n" )); - error = T42_Err_Invalid_File_Format; + error = FT_THROW( Invalid_File_Format ); goto Fail; } @@ -622,18 +663,25 @@ } else { - num_tables = 16 * face->ttf_data[4] + face->ttf_data[5]; - status = BEFORE_TABLE_DIR; - ttf_size = 12 + 16 * num_tables; + num_tables = 16 * face->ttf_data[4] + face->ttf_data[5]; + status = BEFORE_TABLE_DIR; + face->ttf_size = 12 + 16 * num_tables; - if ( FT_REALLOC( face->ttf_data, 12, ttf_size ) ) + if ( (FT_ULong)( limit - parser->root.cursor ) < face->ttf_size ) + { + FT_ERROR(( "t42_parse_sfnts: invalid data in sfnts array\n" )); + error = FT_THROW( Invalid_File_Format ); + goto Fail; + } + + if ( FT_REALLOC( face->ttf_data, 12, face->ttf_size ) ) goto Fail; } /* fall through */ case BEFORE_TABLE_DIR: /* the offset table is read; read the table directory */ - if ( count < ttf_size ) + if ( count < face->ttf_size ) { face->ttf_data[count++] = string_buf[n]; continue; @@ -652,25 +700,24 @@ len = FT_PEEK_ULONG( p ); /* Pad to a 4-byte boundary length */ - ttf_size += ( len + 3 ) & ~3; + face->ttf_size += ( len + 3 ) & ~3; } - status = OTHER_TABLES; - face->ttf_size = ttf_size; + status = OTHER_TABLES; /* there are no more than 256 tables, so no size check here */ if ( FT_REALLOC( face->ttf_data, 12 + 16 * num_tables, - ttf_size + 1 ) ) + face->ttf_size + 1 ) ) goto Fail; } /* fall through */ case OTHER_TABLES: /* all other tables are just copied */ - if ( count >= ttf_size ) + if ( count >= face->ttf_size ) { - FT_ERROR(( "t42_parse_sfnts: too many binary data\n" )); - error = T42_Err_Invalid_File_Format; + FT_ERROR(( "t42_parse_sfnts: too much binary data\n" )); + error = FT_THROW( Invalid_File_Format ); goto Fail; } face->ttf_data[count++] = string_buf[n]; @@ -681,7 +728,7 @@ } /* if control reaches this point, the format was not valid */ - error = T42_Err_Invalid_File_Format; + error = FT_THROW( Invalid_File_Format ); Fail: parser->root.error = error; @@ -717,7 +764,7 @@ if ( parser->root.cursor >= limit ) { FT_ERROR(( "t42_parse_charstrings: out of bounds\n" )); - error = T42_Err_Invalid_File_Format; + error = FT_THROW( Invalid_File_Format ); goto Fail; } @@ -759,14 +806,14 @@ else { FT_ERROR(( "t42_parse_charstrings: invalid token\n" )); - error = T42_Err_Invalid_File_Format; + error = FT_THROW( Invalid_File_Format ); goto Fail; } if ( parser->root.cursor >= limit ) { FT_ERROR(( "t42_parse_charstrings: out of bounds\n" )); - error = T42_Err_Invalid_File_Format; + error = FT_THROW( Invalid_File_Format ); goto Fail; } @@ -815,6 +862,12 @@ break; T1_Skip_PS_Token( parser ); + if ( parser->root.cursor >= limit ) + { + FT_ERROR(( "t42_parse_charstrings: out of bounds\n" )); + error = FT_THROW( Invalid_File_Format ); + goto Fail; + } if ( parser->root.error ) return; @@ -823,10 +876,10 @@ FT_PtrDist len; - if ( cur + 1 >= limit ) + if ( cur + 2 >= limit ) { FT_ERROR(( "t42_parse_charstrings: out of bounds\n" )); - error = T42_Err_Invalid_File_Format; + error = FT_THROW( Invalid_File_Format ); goto Fail; } @@ -857,7 +910,7 @@ if ( parser->root.cursor >= limit ) { FT_ERROR(( "t42_parse_charstrings: out of bounds\n" )); - error = T42_Err_Invalid_File_Format; + error = FT_THROW( Invalid_File_Format ); goto Fail; } @@ -880,7 +933,7 @@ if ( !notdef_found ) { FT_ERROR(( "t42_parse_charstrings: no /.notdef glyph\n" )); - error = T42_Err_Invalid_File_Format; + error = FT_THROW( Invalid_File_Format ); goto Fail; } @@ -1024,7 +1077,7 @@ parser->root.cursor = base; parser->root.limit = base + size; - parser->root.error = T42_Err_Ok; + parser->root.error = FT_Err_Ok; limit = parser->root.limit; -- cgit v1.2.3