From 58b61b6e05597112f8673e5ab9bd175f59e2db5e Mon Sep 17 00:00:00 2001 From: Werner Lemberg Date: Tue, 13 Oct 2015 18:26:18 +0200 Subject: [PATCH] [pcf] Quickly exit if font index < 0. Similar to other font formats, this commit makes the parser no longer check the whole PCF file but only the header and the TOC if we just want to get the number of available faces (and a proper recognition of the font format). * src/pcf/pcfdrivr.c (PCF_Face_Init): Updated. Exit quickly if face_index < 0. * src/pcfread.c (pcf_load_font): Add `face_index' argument. Exit quickly if face_index < 0. * src/pcf/pcf.h: Updated. --- ChangeLog | 17 +++++++++++++++++ src/pcf/pcf.h | 5 +++-- src/pcf/pcfdrivr.c | 8 +++++--- src/pcf/pcfread.c | 15 ++++++++++----- 4 files changed, 35 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index b8a99e2ab..aa5c7b545 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,20 @@ +2015-10-13 Werner Lemberg + + [pcf] Quickly exit if font index < 0. + + Similar to other font formats, this commit makes the parser no + longer check the whole PCF file but only the header and the TOC if + we just want to get the number of available faces (and a proper + recognition of the font format). + + * src/pcf/pcfdrivr.c (PCF_Face_Init): Updated. + Exit quickly if face_index < 0. + + * src/pcfread.c (pcf_load_font): Add `face_index' argument. + Exit quickly if face_index < 0. + + * src/pcf/pcf.h: Updated. + 2015-10-13 Werner Lemberg [ftfuzzer] Handle TTCs and MM/GX variations. diff --git a/src/pcf/pcf.h b/src/pcf/pcf.h index c0da50341..253a33f73 100644 --- a/src/pcf/pcf.h +++ b/src/pcf/pcf.h @@ -226,8 +226,9 @@ FT_BEGIN_HEADER #define GLYPHPADOPTIONS 4 /* I'm not sure about this */ FT_LOCAL( FT_Error ) - pcf_load_font( FT_Stream, - PCF_Face ); + pcf_load_font( FT_Stream stream, + PCF_Face face, + FT_Long face_index ); FT_END_HEADER diff --git a/src/pcf/pcfdrivr.c b/src/pcf/pcfdrivr.c index 8d2ed7cf4..0f4c51828 100644 --- a/src/pcf/pcfdrivr.c +++ b/src/pcf/pcfdrivr.c @@ -271,7 +271,7 @@ THE SOFTWARE. FT_TRACE2(( "PCF driver\n" )); - error = pcf_load_font( stream, face ); + error = pcf_load_font( stream, face, face_index ); if ( error ) { PCF_Face_Done( pcfface ); @@ -332,7 +332,7 @@ THE SOFTWARE. stream = pcfface->stream; - error = pcf_load_font( stream, face ); + error = pcf_load_font( stream, face, face_index ); if ( error ) goto Fail; @@ -351,7 +351,9 @@ THE SOFTWARE. * an invalid argument error when the font could be * opened by the specified driver. */ - if ( face_index > 0 && ( face_index & 0xFFFF ) > 0 ) + if ( face_index < 0 ) + goto Exit; + else if ( face_index > 0 && ( face_index & 0xFFFF ) > 0 ) { FT_ERROR(( "PCF_Face_Init: invalid face index\n" )); PCF_Face_Done( pcfface ); diff --git a/src/pcf/pcfread.c b/src/pcf/pcfread.c index 6a248cfcc..fca677f4f 100644 --- a/src/pcf/pcfread.c +++ b/src/pcf/pcfread.c @@ -1184,8 +1184,10 @@ THE SOFTWARE. FT_LOCAL_DEF( FT_Error ) pcf_load_font( FT_Stream stream, - PCF_Face face ) + PCF_Face face, + FT_Long face_index ) { + FT_Face root = FT_FACE( face ); FT_Error error; FT_Memory memory = FT_FACE( face )->memory; FT_Bool hasBDFAccelerators; @@ -1195,6 +1197,13 @@ THE SOFTWARE. if ( error ) goto Exit; + root->num_faces = 1; + root->face_index = 0; + + /* If we are performing a simple font format check, exit immediately. */ + if ( face_index < 0 ) + return FT_Err_Ok; + error = pcf_get_properties( stream, face ); if ( error ) goto Exit; @@ -1237,13 +1246,9 @@ THE SOFTWARE. /* now construct the face object */ { - FT_Face root = FT_FACE( face ); PCF_Property prop; - root->num_faces = 1; - root->face_index = 0; - root->face_flags |= FT_FACE_FLAG_FIXED_SIZES | FT_FACE_FLAG_HORIZONTAL | FT_FACE_FLAG_FAST_GLYPHS;