summaryrefslogtreecommitdiffstats
path: root/src/3rdparty/freetype/src/type42/t42parse.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/3rdparty/freetype/src/type42/t42parse.c')
-rw-r--r--src/3rdparty/freetype/src/type42/t42parse.c127
1 files changed, 79 insertions, 48 deletions
diff --git a/src/3rdparty/freetype/src/type42/t42parse.c b/src/3rdparty/freetype/src/type42/t42parse.c
index 50708537df..003b63ed77 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-2014 by */
+/* Copyright 2002-2015 by */
/* Roberto Alameda. */
/* */
/* This file is part of the FreeType project, and may only be used, */
@@ -104,12 +104,6 @@
#define T1_Add_Table( p, i, o, l ) (p)->funcs.add( (p), i, o, l )
-#define T1_Done_Table( p ) \
- do \
- { \
- if ( (p)->funcs.done ) \
- (p)->funcs.done( p ); \
- } while ( 0 )
#define T1_Release_Table( p ) \
do \
{ \
@@ -148,11 +142,11 @@
FT_Long size;
- psaux->ps_parser_funcs->init( &parser->root, 0, 0, memory );
+ psaux->ps_parser_funcs->init( &parser->root, NULL, NULL, memory );
parser->stream = stream;
parser->base_len = 0;
- parser->base_dict = 0;
+ parser->base_dict = NULL;
parser->in_memory = 0;
/*******************************************************************/
@@ -184,7 +178,7 @@
if ( error || FT_STREAM_SEEK( 0 ) )
goto Exit;
- size = stream->size;
+ size = (FT_Long)stream->size;
/* now, try to load `size' bytes of the `base' dictionary we */
/* found previously */
@@ -252,13 +246,12 @@
T42_Parser parser = &loader->parser;
FT_Matrix* matrix = &face->type1.font_matrix;
FT_Vector* offset = &face->type1.font_offset;
- 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 );
+ result = T1_ToFixedArray( parser, 6, temp, 0 );
if ( result < 6 )
{
@@ -270,18 +263,12 @@
if ( temp_scale == 0 )
{
- FT_ERROR(( "t1_parse_font_matrix: invalid font matrix\n" ));
+ FT_ERROR(( "t42_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, temp_scale );
-
- /* we need to scale the values by 1.0/temp_scale */
+ /* atypical case */
if ( temp_scale != 0x10000L )
{
temp[0] = FT_DivFix( temp[0], temp_scale );
@@ -345,10 +332,27 @@
else
count = (FT_Int)T1_ToInt( parser );
+ /* only composite fonts (which we don't support) */
+ /* can have larger values */
+ if ( count > 256 )
+ {
+ FT_ERROR(( "t42_parse_encoding: invalid encoding array size\n" ));
+ parser->root.error = FT_THROW( Invalid_File_Format );
+ return;
+ }
+
T1_Skip_Spaces( parser );
if ( parser->root.cursor >= limit )
return;
+ /* PostScript happily allows overwriting of encoding arrays */
+ if ( encode->char_index )
+ {
+ FT_FREE( encode->char_index );
+ FT_FREE( encode->char_name );
+ T1_Release_Table( char_table );
+ }
+
/* we use a T1_Table to store our charnames */
loader->num_chars = encode->num_chars = count;
if ( FT_NEW_ARRAY( encode->char_index, count ) ||
@@ -427,13 +431,20 @@
{
charcode = (FT_Int)T1_ToInt( parser );
T1_Skip_Spaces( parser );
+
+ /* protect against invalid charcode */
+ if ( cur == parser->root.cursor )
+ {
+ parser->root.error = FT_THROW( Unknown_File_Format );
+ return;
+ }
}
cur = parser->root.cursor;
if ( cur + 2 < limit && *cur == '/' && n < count )
{
- FT_PtrDist len;
+ FT_UInt len;
cur++;
@@ -445,7 +456,7 @@
if ( parser->root.error )
return;
- len = parser->root.cursor - cur;
+ len = (FT_UInt)( parser->root.cursor - cur );
parser->root.error = T1_Add_Table( char_table, charcode,
cur, len + 1 );
@@ -461,10 +472,10 @@
/* 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. */
+ /* This encoding array is not valid according to the */
+ /* type42 specification (it might be an encoding for a CID */
+ /* type42 font, however), so we conclude that this font is */
+ /* NOT a type42 font. */
parser->root.error = FT_THROW( Unknown_File_Format );
return;
}
@@ -500,7 +511,7 @@
face->type1.encoding_type = T1_ENCODING_TYPE_ISOLATIN1;
else
- parser->root.error = FT_THROW( Ignore );
+ parser->root.error = FT_ERR( Ignore );
}
}
@@ -524,9 +535,9 @@
FT_Byte* limit = parser->root.limit;
FT_Error error;
FT_Int num_tables = 0;
- FT_ULong count;
+ FT_Long count;
- FT_Long n, string_size, old_string_size, real_size;
+ FT_ULong n, string_size, old_string_size, real_size;
FT_Byte* string_buf = NULL;
FT_Bool allocated = 0;
@@ -579,7 +590,7 @@
goto Exit;
/* don't include delimiters */
- string_size = (FT_Long)( ( parser->root.cursor - cur - 2 + 1 ) / 2 );
+ string_size = (FT_ULong)( ( parser->root.cursor - cur - 2 + 1 ) / 2 );
if ( !string_size )
{
FT_ERROR(( "t42_parse_sfnts: invalid data in sfnts array\n" ));
@@ -594,11 +605,14 @@
parser->root.cursor = cur;
(void)T1_ToBytes( parser, string_buf, string_size, &real_size, 1 );
old_string_size = string_size;
- string_size = real_size;
+ string_size = real_size;
}
else if ( ft_isdigit( *cur ) )
{
+ FT_Long tmp;
+
+
if ( allocated )
{
FT_ERROR(( "t42_parse_sfnts: "
@@ -607,13 +621,15 @@
goto Fail;
}
- string_size = T1_ToInt( parser );
- if ( string_size < 0 )
+ tmp = T1_ToInt( parser );
+ if ( tmp < 0 )
{
FT_ERROR(( "t42_parse_sfnts: invalid string size\n" ));
error = FT_THROW( Invalid_File_Format );
goto Fail;
}
+ else
+ string_size = (FT_ULong)tmp;
T1_Skip_PS_Token( parser ); /* `RD' */
if ( parser->root.error )
@@ -621,7 +637,7 @@
string_buf = parser->root.cursor + 1; /* one space after `RD' */
- if ( limit - parser->root.cursor < string_size )
+ if ( (FT_ULong)( limit - parser->root.cursor ) < string_size )
{
FT_ERROR(( "t42_parse_sfnts: too much binary data\n" ));
error = FT_THROW( Invalid_File_Format );
@@ -667,7 +683,7 @@
status = BEFORE_TABLE_DIR;
face->ttf_size = 12 + 16 * num_tables;
- if ( (FT_ULong)( limit - parser->root.cursor ) < face->ttf_size )
+ if ( (FT_Long)( limit - parser->root.cursor ) < face->ttf_size )
{
FT_ERROR(( "t42_parse_sfnts: invalid data in sfnts array\n" ));
error = FT_THROW( Invalid_File_Format );
@@ -700,7 +716,7 @@
len = FT_PEEK_ULONG( p );
/* Pad to a 4-byte boundary length */
- face->ttf_size += ( len + 3 ) & ~3;
+ face->ttf_size += (FT_Long)( ( len + 3 ) & ~3U );
}
status = OTHER_TABLES;
@@ -754,8 +770,8 @@
FT_Byte* cur;
FT_Byte* limit = parser->root.limit;
- FT_UInt n;
- FT_UInt notdef_index = 0;
+ FT_Int n;
+ FT_Int notdef_index = 0;
FT_Byte notdef_found = 0;
@@ -770,15 +786,21 @@
if ( ft_isdigit( *parser->root.cursor ) )
{
- loader->num_glyphs = (FT_UInt)T1_ToInt( parser );
+ loader->num_glyphs = T1_ToInt( parser );
if ( parser->root.error )
return;
+ if ( loader->num_glyphs < 0 )
+ {
+ FT_ERROR(( "t42_parse_encoding: invalid number of glyphs\n" ));
+ error = FT_THROW( Invalid_File_Format );
+ goto Fail;
+ }
}
else if ( *parser->root.cursor == '<' )
{
/* We have `<< ... >>'. Count the number of `/' in the dictionary */
/* to get its size. */
- FT_UInt count = 0;
+ FT_Int count = 0;
T1_Skip_PS_Token( parser );
@@ -819,6 +841,15 @@
/* initialize tables */
+ /* contrary to Type1, we disallow multiple CharStrings arrays */
+ if ( swap_table->init )
+ {
+ FT_ERROR(( "t42_parse_charstrings:"
+ " only one CharStrings array allowed\n" ));
+ error = FT_THROW( Invalid_File_Format );
+ goto Fail;
+ }
+
error = psaux->ps_table_funcs->init( code_table,
loader->num_glyphs,
memory );
@@ -873,7 +904,7 @@
if ( *cur == '/' )
{
- FT_PtrDist len;
+ FT_UInt len;
if ( cur + 2 >= limit )
@@ -884,7 +915,7 @@
}
cur++; /* skip `/' */
- len = parser->root.cursor - cur;
+ len = (FT_UInt)( parser->root.cursor - cur );
error = T1_Add_Table( name_table, n, cur, len + 1 );
if ( error )
@@ -914,7 +945,7 @@
goto Fail;
}
- len = parser->root.cursor - cur;
+ len = (FT_UInt)( parser->root.cursor - cur );
error = T1_Add_Table( code_table, n, cur, len + 1 );
if ( error )
@@ -1135,7 +1166,7 @@
/* look for immediates */
else if ( *cur == '/' && cur + 2 < limit )
{
- FT_PtrDist len;
+ FT_UInt len;
cur++;
@@ -1145,7 +1176,7 @@
if ( parser->root.error )
goto Exit;
- len = parser->root.cursor - cur;
+ len = (FT_UInt)( parser->root.cursor - cur );
if ( len > 0 && len < 22 && parser->root.cursor < limit )
{
@@ -1164,9 +1195,9 @@
if ( !name )
continue;
- if ( cur[0] == name[0] &&
- len == (FT_PtrDist)ft_strlen( (const char *)name ) &&
- ft_memcmp( cur, name, len ) == 0 )
+ if ( cur[0] == name[0] &&
+ len == ft_strlen( (const char *)name ) &&
+ ft_memcmp( cur, name, len ) == 0 )
{
/* we found it -- run the parsing callback! */
parser->root.error = t42_load_keyword( face,