freetype-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Git][freetype/freetype][master] [sfnt] Streamline POST format 2.0 handi


From: Alexei Podtelezhnikov (@apodtele)
Subject: [Git][freetype/freetype][master] [sfnt] Streamline POST format 2.0 handing (cont'd).
Date: Wed, 29 Mar 2023 04:29:04 +0000

Alexei Podtelezhnikov pushed to branch master at FreeType / FreeType

Commits:

  • 4679fcb6
    by Alexei Podtelezhnikov at 2023-03-29T00:21:00-04:00
    [sfnt] Streamline POST format 2.0 handing (cont'd).
    
    * src/sfnt/ttpost.c (load_format_20): Co-allocate the string data and
    their pointers, which makes it easier to handle and free them.
    (tt_face_free_ps_names): Updated.
    * include/freetype/internal/tttypes.h (TT_Post_20): Update type.
    

2 changed files:

Changes:

  • include/freetype/internal/tttypes.h
    ... ... @@ -803,7 +803,7 @@ FT_BEGIN_HEADER
    803 803
         FT_UShort   num_glyphs;
    
    804 804
         FT_UShort   num_names;
    
    805 805
         FT_UShort*  glyph_indices;
    
    806
    -    FT_Char**   glyph_names;
    
    806
    +    FT_Byte**   glyph_names;
    
    807 807
     
    
    808 808
       } TT_Post_20Rec, *TT_Post_20;
    
    809 809
     
    

  • src/sfnt/ttpost.c
    ... ... @@ -167,8 +167,7 @@
    167 167
         FT_UShort   num_names;
    
    168 168
     
    
    169 169
         FT_UShort*  glyph_indices = NULL;
    
    170
    -    FT_Char**   name_strings  = NULL;
    
    171
    -    FT_Byte*    strings       = NULL;
    
    170
    +    FT_Byte**   name_strings  = NULL;
    
    172 171
     
    
    173 172
     
    
    174 173
         if ( FT_READ_USHORT( num_glyphs ) )
    
    ... ... @@ -229,13 +228,17 @@
    229 228
         {
    
    230 229
           FT_UShort  n;
    
    231 230
           FT_ULong   p;
    
    231
    +      FT_Byte*   strings;
    
    232 232
     
    
    233 233
     
    
    234 234
           post_len -= (FT_ULong)num_glyphs * 2UL + 2;
    
    235 235
     
    
    236
    -      if ( FT_QALLOC( strings, post_len + 1 )       ||
    
    237
    -           FT_STREAM_READ( strings, post_len )      ||
    
    238
    -           FT_QNEW_ARRAY( name_strings, num_names ) )
    
    236
    +      if ( FT_QALLOC( name_strings, num_names * sizeof ( FT_Byte* ) +
    
    237
    +                                    post_len + 1 ) )
    
    238
    +        goto Fail;
    
    239
    +
    
    240
    +      strings = (FT_Byte*)( name_strings + num_names );
    
    241
    +      if ( FT_STREAM_READ( strings, post_len ) )
    
    239 242
             goto Fail;
    
    240 243
     
    
    241 244
           /* convert from Pascal- to C-strings and set pointers */
    
    ... ... @@ -251,7 +254,7 @@
    251 254
             }
    
    252 255
     
    
    253 256
             strings[p]      = 0;
    
    254
    -        name_strings[n] = (FT_Char*)strings + p + 1;
    
    257
    +        name_strings[n] = strings + p + 1;
    
    255 258
             p              += len + 1;
    
    256 259
           }
    
    257 260
           strings[post_len] = 0;
    
    ... ... @@ -259,22 +262,11 @@
    259 262
           /* deal with missing or insufficient string data */
    
    260 263
           if ( n < num_names )
    
    261 264
           {
    
    262
    -        if ( post_len == 0 )
    
    263
    -        {
    
    264
    -          /* fake empty string */
    
    265
    -          if ( FT_QREALLOC( strings, 1, 2 ) )
    
    266
    -            goto Fail;
    
    265
    +        FT_TRACE4(( "load_format_20: %hu PostScript names are truncated\n",
    
    266
    +                    num_names - n ));
    
    267 267
     
    
    268
    -          post_len          = 1;
    
    269
    -          strings[post_len] = 0;
    
    270
    -        }
    
    271
    -
    
    272
    -        FT_ERROR(( "load_format_20:"
    
    273
    -                   " all entries in post table are already parsed,"
    
    274
    -                   " using NULL names for gid %d - %d\n",
    
    275
    -                    n, num_names - 1 ));
    
    276 268
             for ( ; n < num_names; n++ )
    
    277
    -          name_strings[n] = (FT_Char*)strings + post_len;
    
    269
    +          name_strings[n] = strings + post_len;
    
    278 270
           }
    
    279 271
         }
    
    280 272
     
    
    ... ... @@ -292,7 +284,6 @@
    292 284
     
    
    293 285
       Fail:
    
    294 286
         FT_FREE( name_strings );
    
    295
    -    FT_FREE( strings );
    
    296 287
         FT_FREE( glyph_indices );
    
    297 288
     
    
    298 289
       Exit:
    
    ... ... @@ -427,9 +418,6 @@
    427 418
     
    
    428 419
             if ( table->num_names )
    
    429 420
             {
    
    430
    -          table->glyph_names[0]--;
    
    431
    -          FT_FREE( table->glyph_names[0] );
    
    432
    -
    
    433 421
               FT_FREE( table->glyph_names );
    
    434 422
               table->num_names = 0;
    
    435 423
             }
    


  • reply via email to

    [Prev in Thread] Current Thread [Next in Thread]