freetype-commit
[Top][All Lists]
Advanced

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

[Git][freetype/freetype][master] [woff, woff2] Avoid buffer zeroing.


From: Alexei Podtelezhnikov (@apodtele)
Subject: [Git][freetype/freetype][master] [woff, woff2] Avoid buffer zeroing.
Date: Sat, 11 Jun 2022 20:15:58 +0000

Alexei Podtelezhnikov pushed to branch master at FreeType / FreeType

Commits:

  • 73631b95
    by Alexei Podtelezhnikov at 2022-06-11T16:10:40-04:00
    [woff, woff2] Avoid buffer zeroing.
    
    * src/sfnt/sfwoff.c (woff_open_font): Use Q-macros.
    * src/sfnt/sfwoff2.c: Ditto.
    (reconstruct_font): Allocate table_entry on stack.
    

2 changed files:

Changes:

  • src/sfnt/sfwoff.c
    ... ... @@ -196,8 +196,8 @@
    196 196
         /* tag value, the tables themselves are not.  We thus have to */
    
    197 197
         /* sort them by offset and check that they don't overlap.     */
    
    198 198
     
    
    199
    -    if ( FT_NEW_ARRAY( tables, woff.num_tables )  ||
    
    200
    -         FT_NEW_ARRAY( indices, woff.num_tables ) )
    
    199
    +    if ( FT_QNEW_ARRAY( tables, woff.num_tables )  ||
    
    200
    +         FT_QNEW_ARRAY( indices, woff.num_tables ) )
    
    201 201
           goto Exit;
    
    202 202
     
    
    203 203
         FT_TRACE2(( "\n" ));
    
    ... ... @@ -328,9 +328,9 @@
    328 328
         }
    
    329 329
     
    
    330 330
         /* Now use `totalSfntSize'. */
    
    331
    -    if ( FT_REALLOC( sfnt,
    
    332
    -                     12 + woff.num_tables * 16UL,
    
    333
    -                     woff.totalSfntSize ) )
    
    331
    +    if ( FT_QREALLOC( sfnt,
    
    332
    +                      12 + woff.num_tables * 16UL,
    
    333
    +                      woff.totalSfntSize ) )
    
    334 334
           goto Exit;
    
    335 335
     
    
    336 336
         sfnt_header = sfnt + 12;
    

  • src/sfnt/sfwoff2.c
    ... ... @@ -229,9 +229,9 @@
    229 229
         {
    
    230 230
           FT_TRACE6(( "Reallocating %lu to %lu.\n",
    
    231 231
                       *dst_size, (*offset + size) ));
    
    232
    -      if ( FT_REALLOC( dst,
    
    233
    -                       (FT_ULong)( *dst_size ),
    
    234
    -                       (FT_ULong)( *offset + size ) ) )
    
    232
    +      if ( FT_QREALLOC( dst,
    
    233
    +                        (FT_ULong)( *dst_size ),
    
    234
    +                        (FT_ULong)( *offset + size ) ) )
    
    235 235
             goto Exit;
    
    236 236
     
    
    237 237
           *dst_size = *offset + size;
    
    ... ... @@ -784,7 +784,7 @@
    784 784
           goto Fail;
    
    785 785
     
    
    786 786
         loca_buf_size = loca_values_size * offset_size;
    
    787
    -    if ( FT_QNEW_ARRAY( loca_buf, loca_buf_size ) )
    
    787
    +    if ( FT_QALLOC( loca_buf, loca_buf_size ) )
    
    788 788
           goto Fail;
    
    789 789
     
    
    790 790
         dst = loca_buf;
    
    ... ... @@ -863,7 +863,7 @@
    863 863
         WOFF2_Point  points       = NULL;
    
    864 864
     
    
    865 865
     
    
    866
    -    if ( FT_NEW_ARRAY( substreams, num_substreams ) )
    
    866
    +    if ( FT_QNEW_ARRAY( substreams, num_substreams ) )
    
    867 867
           goto Fail;
    
    868 868
     
    
    869 869
         if ( FT_STREAM_SKIP( 2 ) )
    
    ... ... @@ -926,7 +926,7 @@
    926 926
           offset += overlap_bitmap_length;
    
    927 927
         }
    
    928 928
     
    
    929
    -    if ( FT_NEW_ARRAY( loca_values, num_glyphs + 1 ) )
    
    929
    +    if ( FT_QNEW_ARRAY( loca_values, num_glyphs + 1 ) )
    
    930 930
           goto Fail;
    
    931 931
     
    
    932 932
         points_size        = 0;
    
    ... ... @@ -938,10 +938,10 @@
    938 938
         substreams[BBOX_STREAM].offset += bbox_bitmap_length;
    
    939 939
     
    
    940 940
         glyph_buf_size = WOFF2_DEFAULT_GLYPH_BUF;
    
    941
    -    if ( FT_NEW_ARRAY( glyph_buf, glyph_buf_size ) )
    
    941
    +    if ( FT_QALLOC( glyph_buf, glyph_buf_size ) )
    
    942 942
           goto Fail;
    
    943 943
     
    
    944
    -    if ( FT_NEW_ARRAY( info->x_mins, num_glyphs ) )
    
    944
    +    if ( FT_QNEW_ARRAY( info->x_mins, num_glyphs ) )
    
    945 945
           goto Fail;
    
    946 946
     
    
    947 947
         for ( i = 0; i < num_glyphs; ++i )
    
    ... ... @@ -999,7 +999,7 @@
    999 999
             size_needed = 12 + composite_size + instruction_size;
    
    1000 1000
             if ( glyph_buf_size < size_needed )
    
    1001 1001
             {
    
    1002
    -          if ( FT_RENEW_ARRAY( glyph_buf, glyph_buf_size, size_needed ) )
    
    1002
    +          if ( FT_QREALLOC( glyph_buf, glyph_buf_size, size_needed ) )
    
    1003 1003
                 goto Fail;
    
    1004 1004
               glyph_buf_size = size_needed;
    
    1005 1005
             }
    
    ... ... @@ -1075,7 +1075,7 @@
    1075 1075
                 have_overlap = TRUE;
    
    1076 1076
             }
    
    1077 1077
     
    
    1078
    -        if ( FT_NEW_ARRAY( n_points_arr, n_contours ) )
    
    1078
    +        if ( FT_QNEW_ARRAY( n_points_arr, n_contours ) )
    
    1079 1079
               goto Fail;
    
    1080 1080
     
    
    1081 1081
             if ( FT_STREAM_SEEK( substreams[N_POINTS_STREAM].offset ) )
    
    ... ... @@ -1112,7 +1112,7 @@
    1112 1112
     
    
    1113 1113
             /* Create array to store point information. */
    
    1114 1114
             points_size = total_n_points;
    
    1115
    -        if ( FT_NEW_ARRAY( points, points_size ) )
    
    1115
    +        if ( FT_QNEW_ARRAY( points, points_size ) )
    
    1116 1116
               goto Fail;
    
    1117 1117
     
    
    1118 1118
             if ( triplet_decode( flags_buf,
    
    ... ... @@ -1141,7 +1141,7 @@
    1141 1141
                           instruction_size;
    
    1142 1142
             if ( glyph_buf_size < size_needed )
    
    1143 1143
             {
    
    1144
    -          if ( FT_RENEW_ARRAY( glyph_buf, glyph_buf_size, size_needed ) )
    
    1144
    +          if ( FT_QREALLOC( glyph_buf, glyph_buf_size, size_needed ) )
    
    1145 1145
                 goto Fail;
    
    1146 1146
               glyph_buf_size = size_needed;
    
    1147 1147
             }
    
    ... ... @@ -1226,8 +1226,7 @@
    1226 1226
           *glyf_checksum += compute_ULong_sum( glyph_buf, glyph_size );
    
    1227 1227
     
    
    1228 1228
           /* Store x_mins, may be required to reconstruct `hmtx'. */
    
    1229
    -      if ( n_contours > 0 )
    
    1230
    -        info->x_mins[i] = (FT_Short)x_min;
    
    1229
    +      info->x_mins[i] = (FT_Short)x_min;
    
    1231 1230
         }
    
    1232 1231
     
    
    1233 1232
         info->glyf_table->dst_length = dest_offset - info->glyf_table->dst_offset;
    
    ... ... @@ -1344,7 +1343,7 @@
    1344 1343
         offset_size = index_format ? 4 : 2;
    
    1345 1344
     
    
    1346 1345
         /* Create `x_mins' array. */
    
    1347
    -    if ( FT_NEW_ARRAY( info->x_mins, num_glyphs ) )
    
    1346
    +    if ( FT_QNEW_ARRAY( info->x_mins, num_glyphs ) )
    
    1348 1347
           return error;
    
    1349 1348
     
    
    1350 1349
         loca_offset = info->loca_table->src_offset;
    
    ... ... @@ -1432,8 +1431,8 @@
    1432 1431
         if ( num_hmetrics < 1 )
    
    1433 1432
           goto Fail;
    
    1434 1433
     
    
    1435
    -    if ( FT_NEW_ARRAY( advance_widths, num_hmetrics ) ||
    
    1436
    -         FT_NEW_ARRAY( lsbs, num_glyphs )             )
    
    1434
    +    if ( FT_QNEW_ARRAY( advance_widths, num_hmetrics ) ||
    
    1435
    +         FT_QNEW_ARRAY( lsbs, num_glyphs )             )
    
    1437 1436
           goto Fail;
    
    1438 1437
     
    
    1439 1438
         /* Read `advanceWidth' stream.  Always present. */
    
    ... ... @@ -1484,7 +1483,7 @@
    1484 1483
     
    
    1485 1484
         /* Build the hmtx table. */
    
    1486 1485
         hmtx_table_size = 2 * num_hmetrics + 2 * num_glyphs;
    
    1487
    -    if ( FT_NEW_ARRAY( hmtx_table, hmtx_table_size ) )
    
    1486
    +    if ( FT_QALLOC( hmtx_table, hmtx_table_size ) )
    
    1488 1487
           goto Fail;
    
    1489 1488
     
    
    1490 1489
         dst = hmtx_table;
    
    ... ... @@ -1541,10 +1540,10 @@
    1541 1540
       {
    
    1542 1541
         /* Memory management of `transformed_buf' is handled by the caller. */
    
    1543 1542
     
    
    1544
    -    FT_Error   error       = FT_Err_Ok;
    
    1545
    -    FT_Stream  stream      = NULL;
    
    1546
    -    FT_Byte*   buf_cursor  = NULL;
    
    1547
    -    FT_Byte*   table_entry = NULL;
    
    1543
    +    FT_Error   error      = FT_Err_Ok;
    
    1544
    +    FT_Stream  stream     = NULL;
    
    1545
    +    FT_Byte*   buf_cursor = NULL;
    
    1546
    +    FT_Byte    table_entry[16];
    
    1548 1547
     
    
    1549 1548
         /* We are reallocating memory for `sfnt', so its pointer may change. */
    
    1550 1549
         FT_Byte*   sfnt = *sfnt_bytes;
    
    ... ... @@ -1585,10 +1584,6 @@
    1585 1584
           }
    
    1586 1585
         }
    
    1587 1586
     
    
    1588
    -    /* Create buffer for table entries. */
    
    1589
    -    if ( FT_NEW_ARRAY( table_entry, 16 ) )
    
    1590
    -      goto Fail;
    
    1591
    -
    
    1592 1587
         /* Create a stream for the uncompressed buffer. */
    
    1593 1588
         if ( FT_NEW( stream ) )
    
    1594 1589
           goto Fail;
    
    ... ... @@ -1751,7 +1746,6 @@
    1751 1746
         /* Set pointer of sfnt stream to its correct value. */
    
    1752 1747
         *sfnt_bytes = sfnt;
    
    1753 1748
     
    
    1754
    -    FT_FREE( table_entry );
    
    1755 1749
         FT_Stream_Close( stream );
    
    1756 1750
         FT_FREE( stream );
    
    1757 1751
     
    
    ... ... @@ -1764,7 +1758,6 @@
    1764 1758
         /* Set pointer of sfnt stream to its correct value. */
    
    1765 1759
         *sfnt_bytes = sfnt;
    
    1766 1760
     
    
    1767
    -    FT_FREE( table_entry );
    
    1768 1761
         FT_Stream_Close( stream );
    
    1769 1762
         FT_FREE( stream );
    
    1770 1763
     
    
    ... ... @@ -1877,8 +1870,8 @@
    1877 1870
         woff2.ttc_fonts = NULL;
    
    1878 1871
     
    
    1879 1872
         /* Read table directory. */
    
    1880
    -    if ( FT_NEW_ARRAY( tables, woff2.num_tables )  ||
    
    1881
    -         FT_NEW_ARRAY( indices, woff2.num_tables ) )
    
    1873
    +    if ( FT_QNEW_ARRAY( tables, woff2.num_tables )  ||
    
    1874
    +         FT_QNEW_ARRAY( indices, woff2.num_tables ) )
    
    1882 1875
           goto Exit;
    
    1883 1876
     
    
    1884 1877
         FT_TRACE2(( "\n" ));
    
    ... ... @@ -1949,10 +1942,11 @@
    1949 1942
             goto Exit;
    
    1950 1943
           }
    
    1951 1944
     
    
    1945
    +      table->flags      = flags;
    
    1952 1946
           table->src_offset = src_offset;
    
    1953 1947
           table->src_length = table->TransformLength;
    
    1954 1948
           src_offset       += table->TransformLength;
    
    1955
    -      table->flags      = flags;
    
    1949
    +      table->dst_offset = 0;
    
    1956 1950
     
    
    1957 1951
           FT_TRACE2(( "  %c%c%c%c  %08d  %08d   %08ld    %08ld    %08ld\n",
    
    1958 1952
                       (FT_Char)( table->Tag >> 24 ),
    
    ... ... @@ -2010,7 +2004,7 @@
    2010 2004
     
    
    2011 2005
           FT_TRACE4(( "Number of fonts in TTC: %d\n", woff2.num_fonts ));
    
    2012 2006
     
    
    2013
    -      if ( FT_NEW_ARRAY( woff2.ttc_fonts, woff2.num_fonts ) )
    
    2007
    +      if ( FT_QNEW_ARRAY( woff2.ttc_fonts, woff2.num_fonts ) )
    
    2014 2008
             goto Exit;
    
    2015 2009
     
    
    2016 2010
           for ( nn = 0; nn < woff2.num_fonts; nn++ )
    
    ... ... @@ -2023,7 +2017,7 @@
    2023 2017
             if ( FT_READ_ULONG( ttc_font->flavor ) )
    
    2024 2018
               goto Exit;
    
    2025 2019
     
    
    2026
    -        if ( FT_NEW_ARRAY( ttc_font->table_indices, ttc_font->num_tables ) )
    
    2020
    +        if ( FT_QNEW_ARRAY( ttc_font->table_indices, ttc_font->num_tables ) )
    
    2027 2021
               goto Exit;
    
    2028 2022
     
    
    2029 2023
             FT_TRACE5(( "Number of tables in font %d: %d\n",
    
    ... ... @@ -2302,9 +2296,9 @@
    2302 2296
         {
    
    2303 2297
           FT_TRACE5(( "Trimming sfnt stream from %lu to %lu.\n",
    
    2304 2298
                       sfnt_size, woff2.actual_sfnt_size ));
    
    2305
    -      if ( FT_REALLOC( sfnt,
    
    2306
    -                       (FT_ULong)( sfnt_size ),
    
    2307
    -                       (FT_ULong)( woff2.actual_sfnt_size ) ) )
    
    2299
    +      if ( FT_QREALLOC( sfnt,
    
    2300
    +                        (FT_ULong)( sfnt_size ),
    
    2301
    +                        (FT_ULong)( woff2.actual_sfnt_size ) ) )
    
    2308 2302
             goto Exit;
    
    2309 2303
         }
    
    2310 2304
     
    


  • reply via email to

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