[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.
This commit is contained in:
Werner Lemberg 2015-02-18 11:38:46 +01:00
parent 6bd7d28fc7
commit 272e3cd077
6 changed files with 49 additions and 18 deletions

View File

@ -1,3 +1,20 @@
2015-02-18 Werner Lemberg <wl@gnu.org>
[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 <wl@gnu.org>
Don't use `FT_PtrDist' for lengths.

View File

@ -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;

View File

@ -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 );

View File

@ -61,6 +61,7 @@ FT_BEGIN_HEADER
char* s;
FT_Fixed f;
FT_Int i;
FT_UInt u;
FT_Bool b;
} u;

View File

@ -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",

View File

@ -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 )