From 272e3cd077c561ca8fa452be4b3fed41818d2d8d Mon Sep 17 00:00:00 2001 From: Werner Lemberg Date: Wed, 18 Feb 2015 11:38:46 +0100 Subject: [PATCH] [psaux, type1] Fix minor AFM issues. * include/internal/t1types.h (AFM_KernPairRec): Make indices unsigned. Update users. (AFM_FontInfoRec): Make element counters unsigned. Update users. * src/psaux/afmparse.h (AFM_ValueRec): Add union member for unsigned int. * src/psaux/afmparse.c (afm_parse_track_kern, afm_parse_kern_pairs): Reject negative values for number of kerning elements. * src/type1/t1afm.c, src/tools/test_afm.c: Updated. --- ChangeLog | 17 +++++++++++++++++ include/internal/t1types.h | 12 ++++++------ src/psaux/afmparse.c | 29 +++++++++++++++++++++-------- src/psaux/afmparse.h | 1 + src/tools/test_afm.c | 2 +- src/type1/t1afm.c | 6 +++--- 6 files changed, 49 insertions(+), 18 deletions(-) diff --git a/ChangeLog b/ChangeLog index 723e5c9d2..40fa27a8d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,20 @@ +2015-02-18 Werner Lemberg + + [psaux, type1] Fix minor AFM issues. + + * include/internal/t1types.h (AFM_KernPairRec): Make indices + unsigned. + Update users. + (AFM_FontInfoRec): Make element counters unsigned. + Update users. + * src/psaux/afmparse.h (AFM_ValueRec): Add union member for unsigned + int. + + * src/psaux/afmparse.c (afm_parse_track_kern, afm_parse_kern_pairs): + Reject negative values for number of kerning elements. + + * src/type1/t1afm.c, src/tools/test_afm.c: Updated. + 2015-02-18 Werner Lemberg Don't use `FT_PtrDist' for lengths. diff --git a/include/internal/t1types.h b/include/internal/t1types.h index 0953fa5d5..5e5fd77ef 100644 --- a/include/internal/t1types.h +++ b/include/internal/t1types.h @@ -157,10 +157,10 @@ FT_BEGIN_HEADER typedef struct AFM_KernPairRec_ { - FT_Int index1; - FT_Int index2; - FT_Int x; - FT_Int y; + FT_UInt index1; + FT_UInt index2; + FT_Int x; + FT_Int y; } AFM_KernPairRec, *AFM_KernPair; @@ -171,9 +171,9 @@ FT_BEGIN_HEADER FT_Fixed Ascender; FT_Fixed Descender; AFM_TrackKern TrackKerns; /* free if non-NULL */ - FT_Int NumTrackKern; + FT_UInt NumTrackKern; AFM_KernPair KernPairs; /* free if non-NULL */ - FT_Int NumKernPair; + FT_UInt NumKernPair; } AFM_FontInfoRec, *AFM_FontInfo; diff --git a/src/psaux/afmparse.c b/src/psaux/afmparse.c index c9bcfcf84..5427b4cda 100644 --- a/src/psaux/afmparse.c +++ b/src/psaux/afmparse.c @@ -590,11 +590,17 @@ char* key; FT_Offset len; int n = -1; + FT_Int tmp; - if ( afm_parser_read_int( parser, &fi->NumTrackKern ) ) + if ( afm_parser_read_int( parser, &tmp ) ) goto Fail; + if ( tmp < 0 ) + goto Fail; + + fi->NumTrackKern = (FT_UInt)tmp; + if ( fi->NumTrackKern ) { FT_Memory memory = parser->memory; @@ -615,7 +621,7 @@ case AFM_TOKEN_TRACKKERN: n++; - if ( n >= fi->NumTrackKern ) + if ( n >= (int)fi->NumTrackKern ) goto Fail; tk = fi->TrackKerns + n; @@ -639,7 +645,7 @@ case AFM_TOKEN_ENDTRACKKERN: case AFM_TOKEN_ENDKERNDATA: case AFM_TOKEN_ENDFONTMETRICS: - fi->NumTrackKern = n + 1; + fi->NumTrackKern = (FT_UInt)( n + 1 ); return FT_Err_Ok; case AFM_TOKEN_UNKNOWN: @@ -688,11 +694,17 @@ char* key; FT_Offset len; int n = -1; + FT_Int tmp; - if ( afm_parser_read_int( parser, &fi->NumKernPair ) ) + if ( afm_parser_read_int( parser, &tmp ) ) goto Fail; + if ( tmp < 0 ) + goto Fail; + + fi->NumKernPair = (FT_UInt)tmp; + if ( fi->NumKernPair ) { FT_Memory memory = parser->memory; @@ -720,7 +732,7 @@ n++; - if ( n >= fi->NumKernPair ) + if ( n >= (int)fi->NumKernPair ) goto Fail; kp = fi->KernPairs + n; @@ -733,8 +745,9 @@ if ( r < 3 ) goto Fail; - kp->index1 = shared_vals[0].u.i; - kp->index2 = shared_vals[1].u.i; + /* index values can't be negative */ + kp->index1 = shared_vals[0].u.u; + kp->index2 = shared_vals[1].u.u; if ( token == AFM_TOKEN_KPY ) { kp->x = 0; @@ -752,7 +765,7 @@ case AFM_TOKEN_ENDKERNPAIRS: case AFM_TOKEN_ENDKERNDATA: case AFM_TOKEN_ENDFONTMETRICS: - fi->NumKernPair = n + 1; + fi->NumKernPair = (FT_UInt)( n + 1 ); ft_qsort( fi->KernPairs, fi->NumKernPair, sizeof ( AFM_KernPairRec ), afm_compare_kern_pairs ); diff --git a/src/psaux/afmparse.h b/src/psaux/afmparse.h index 155eb40d9..ac1982e5f 100644 --- a/src/psaux/afmparse.h +++ b/src/psaux/afmparse.h @@ -61,6 +61,7 @@ FT_BEGIN_HEADER char* s; FT_Fixed f; FT_Int i; + FT_UInt u; FT_Bool b; } u; diff --git a/src/tools/test_afm.c b/src/tools/test_afm.c index 24cd0c4f0..8de619bb0 100644 --- a/src/tools/test_afm.c +++ b/src/tools/test_afm.c @@ -9,7 +9,7 @@ void dump_fontinfo( AFM_FontInfo fi ) { - FT_Int i; + FT_UInt i; printf( "This AFM is for %sCID font.\n\n", diff --git a/src/type1/t1afm.c b/src/type1/t1afm.c index 35f67e8c4..7f32059f8 100644 --- a/src/type1/t1afm.c +++ b/src/type1/t1afm.c @@ -169,8 +169,8 @@ goto Exit; /* now, read each kern pair */ - kp = fi->KernPairs; - limit = p + 4 * fi->NumKernPair; + kp = fi->KernPairs; + limit = p + 4 * fi->NumKernPair; /* PFM kerning data are stored by encoding rather than glyph index, */ /* so find the PostScript charmap of this font and install it */ @@ -362,7 +362,7 @@ FT_Fixed* kerning ) { AFM_FontInfo fi = (AFM_FontInfo)( (T1_Face)face )->afm_data; - FT_Int i; + FT_UInt i; if ( !fi )