diff options
Diffstat (limited to 'modules/freetype2/src/tools/ftfuzzer/ftfuzzer.cc')
-rw-r--r-- | modules/freetype2/src/tools/ftfuzzer/ftfuzzer.cc | 100 |
1 files changed, 70 insertions, 30 deletions
diff --git a/modules/freetype2/src/tools/ftfuzzer/ftfuzzer.cc b/modules/freetype2/src/tools/ftfuzzer/ftfuzzer.cc index 31834a5f9..acf2bc982 100644 --- a/modules/freetype2/src/tools/ftfuzzer/ftfuzzer.cc +++ b/modules/freetype2/src/tools/ftfuzzer/ftfuzzer.cc @@ -2,7 +2,7 @@ // // A fuzzing function to test FreeType with libFuzzer. // -// Copyright 2015-2016 by +// Copyright 2015-2018 by // David Turner, Robert Wilhelm, and Werner Lemberg. // // This file is part of the FreeType project, and may only be used, @@ -43,8 +43,7 @@ #include FT_OUTLINE_H #include FT_BBOX_H #include FT_MODULE_H -#include FT_CFF_DRIVER_H -#include FT_TRUETYPE_DRIVER_H +#include FT_DRIVER_H #include FT_MULTIPLE_MASTERS_H @@ -61,7 +60,7 @@ return; // try to activate Adobe's CFF engine; it might not be the default - unsigned int cff_hinting_engine = FT_CFF_HINTING_ADOBE; + unsigned int cff_hinting_engine = FT_HINTING_ADOBE; FT_Property_Set( library, "cff", "hinting-engine", &cff_hinting_engine ); @@ -76,7 +75,7 @@ FT_Global global_ft; - // We want to select n values at random (without repitition), + // We want to select n values at random (without repetition), // with 0 < n <= N. The algorithm is taken from TAoCP, Vol. 2 // (Algorithm S, selection sampling technique) struct Random @@ -270,11 +269,20 @@ long num_faces = face->num_faces; FT_Done_Face( face ); - // loop over all faces - for ( long face_index = 0; - face_index < num_faces; - face_index++ ) + // loop over up to 20 arbitrarily selected faces + // from index range [0;num-faces-1] + long max_face_cnt = num_faces < 20 + ? num_faces + : 20; + + Random faces_pool( (int)max_face_cnt, (int)num_faces ); + + for ( long face_cnt = 0; + face_cnt < max_face_cnt; + face_cnt++ ) { + long face_index = faces_pool.get() - 1; + // get number of instances if ( FT_New_Memory_Face( library, files[0].data(), @@ -285,17 +293,41 @@ long num_instances = face->style_flags >> 16; FT_Done_Face( face ); - // load face with and without instances - for ( long instance_index = 0; - instance_index < num_instances + 1; - instance_index++ ) + // loop over the face without instance (index 0) + // and up to 20 arbitrarily selected instances + // from index range [1;num_instances] + long max_instance_cnt = num_instances < 20 + ? num_instances + : 20; + + Random instances_pool( (int)max_instance_cnt, (int)num_instances ); + + for ( long instance_cnt = 0; + instance_cnt <= max_instance_cnt; + instance_cnt++ ) { - if ( FT_New_Memory_Face( library, - files[0].data(), - (FT_Long)files[0].size(), - ( instance_index << 16 ) + face_index, - &face ) ) - continue; + long instance_index = 0; + + if ( !instance_cnt ) + { + if ( FT_New_Memory_Face( library, + files[0].data(), + (FT_Long)files[0].size(), + face_index, + &face ) ) + continue; + } + else + { + instance_index = instances_pool.get(); + + if ( FT_New_Memory_Face( library, + files[0].data(), + (FT_Long)files[0].size(), + ( instance_index << 16 ) + face_index, + &face ) ) + continue; + } // if we have more than a single input file coming from an archive, // attach them (starting with the second file) using the order given @@ -314,19 +346,24 @@ FT_Attach_Stream( face, &open_args ); } - // loop over an arbitrary size for outlines (index 0) - // and up to ten arbitrarily selected bitmap stroke sizes (index 1-10) - int max_idx = face->num_fixed_sizes < 10 - ? face->num_fixed_sizes - : 10; + // loop over an arbitrary size for outlines + // and up to ten arbitrarily selected bitmap strike sizes + // from the range [0;num_fixed_sizes - 1] + int max_size_cnt = face->num_fixed_sizes < 10 + ? face->num_fixed_sizes + : 10; - Random pool( max_idx, face->num_fixed_sizes ); + Random sizes_pool( max_size_cnt, face->num_fixed_sizes ); - for ( int idx = 0; idx <= max_idx; idx++ ) + for ( int size_cnt = 0; + size_cnt <= max_size_cnt; + size_cnt++ ) { FT_Int32 flags = load_flags; - if ( !idx ) + int size_index = 0; + + if ( !size_cnt ) { // set up 20pt at 72dpi as an arbitrary size if ( FT_Set_Char_Size( face, 20 * 64, 20 * 64, 72, 72 ) ) @@ -335,17 +372,20 @@ } else { - // bitmap strokes are not active for glyph variations + // bitmap strikes are not active for font variations if ( instance_index ) continue; - if ( FT_Select_Size( face, pool.get() - 1 ) ) + size_index = sizes_pool.get() - 1; + + if ( FT_Select_Size( face, size_index ) ) continue; flags |= FT_LOAD_COLOR; } // test MM interface only for a face without a selected instance - if ( instance_index == 0 ) + // and without a selected bitmap strike + if ( !instance_index && !size_cnt ) setIntermediateAxis( face ); // loop over all glyphs |