Skip to content

Commit

Permalink
[bdf, cid, pfr, winfonts] Improve rejection of other font formats.
Browse files Browse the repository at this point in the history
This is mainly for better diagnostics of malformed fonts.

* src/bdf/bdflib.c (_bfd_readstream): Stop font format testing if the first
input line is too long or doesn't end with `\r` or `\n`.

* src/cid/cidparse.c (cid_parser_new): Don't handle too short input as an
error but as an unknown format.

* src/pfr/pfrobjs.c (pfr_face_init): Ditto.

* src/winfonts/winfnt.c (fnt_font_load, fnt_face_get_dll_font): Ditto.
  • Loading branch information
lemzwerg committed Oct 19, 2021
1 parent 38b349c commit 8ef8072
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/bdf/bdflib.c
Original file line number Diff line number Diff line change
Expand Up @@ -581,8 +581,14 @@
/* or even resizing it */
if ( end >= avail )
{
if ( bytes == 0 ) /* last line in file doesn't end in \r or \n */
break; /* ignore it then exit */
if ( bytes == 0 )
{
/* last line in file doesn't end in \r or \n; */
/* ignore it then exit */
if ( lineno == 1 )
error = FT_THROW( Missing_Startfont_Field );
break;
}

if ( start == 0 )
{
Expand All @@ -593,8 +599,13 @@

if ( buf_size >= 65536UL ) /* limit ourselves to 64KByte */
{
FT_ERROR(( "_bdf_readstream: " ERRMSG6, lineno ));
error = FT_THROW( Invalid_Argument );
if ( lineno == 1 )
error = FT_THROW( Missing_Startfont_Field );
else
{
FT_ERROR(( "_bdf_readstream: " ERRMSG6, lineno ));
error = FT_THROW( Invalid_Argument );
}
goto Exit;
}

Expand Down Expand Up @@ -2169,7 +2180,7 @@
unsigned long lineno = 0; /* make compiler happy */
_bdf_parse_t *p = NULL;

FT_Error error = FT_Err_Ok;
FT_Error error = FT_Err_Ok;


if ( FT_NEW( p ) )
Expand Down
4 changes: 4 additions & 0 deletions src/cid/cidparse.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@

/* first of all, check the font format in the header */
if ( FT_FRAME_ENTER( 31 ) )
{
FT_TRACE2(( " not a CID-keyed font\n" ));
error = FT_THROW( Unknown_File_Format );
goto Exit;
}

if ( ft_strncmp( (char *)stream->cursor,
"%!PS-Adobe-3.0 Resource-CIDFont", 31 ) )
Expand Down
4 changes: 4 additions & 0 deletions src/pfr/pfrobjs.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,11 @@
/* load the header and check it */
error = pfr_header_load( &face->header, stream );
if ( error )
{
FT_TRACE2(( " not a PFR font\n" ));
error = FT_THROW( Unknown_File_Format );
goto Exit;
}

if ( !pfr_header_check( &face->header ) )
{
Expand Down
7 changes: 7 additions & 0 deletions src/winfonts/winfnt.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,11 @@
/* first of all, read the FNT header */
if ( FT_STREAM_SEEK( font->offset ) ||
FT_STREAM_READ_FIELDS( winfnt_header_fields, header ) )
{
FT_TRACE2(( " not a Windows FNT file\n" ));
error = FT_THROW( Unknown_File_Format );
goto Exit;
}

/* check header */
if ( header->version != 0x200 &&
Expand Down Expand Up @@ -284,7 +288,10 @@
/* does it begin with an MZ header? */
if ( FT_STREAM_SEEK( 0 ) ||
FT_STREAM_READ_FIELDS( winmz_header_fields, &mz_header ) )
{
error = FT_ERR( Unknown_File_Format );
goto Exit;
}

error = FT_ERR( Unknown_File_Format );
if ( mz_header.magic == WINFNT_MZ_MAGIC )
Expand Down

0 comments on commit 8ef8072

Please sign in to comment.