3 // A fuzzing function to test FreeType's rasterizers with libFuzzer.
6 // David Turner, Robert Wilhelm, and Werner Lemberg.
8 // This file is part of the FreeType project, and may only be used,
9 // modified, and distributed under the terms of the FreeType project
10 // license, LICENSE.TXT. By continuing to use, modify, or distribute
11 // this file you indicate that you have read the license and
12 // understand and accept it fully.
25 #include FT_FREETYPE_H
30 static FT_Library library;
31 static int InitResult;
36 InitResult = FT_Init_FreeType( &library );
39 FT_Done_FreeType( library );
47 LLVMFuzzerTestOneInput( const uint8_t* data,
50 unsigned char pixels[4];
52 FT_Bitmap bitmap_mono = {
58 FT_PIXEL_MODE_MONO, // pixel_mode
63 FT_Bitmap bitmap_gray = {
69 FT_PIXEL_MODE_GRAY, // pixel_mode
74 const size_t vsize = sizeof ( FT_Vector );
75 const size_t tsize = sizeof ( char );
77 // we use the input data for both points and tags
78 short n_points = short( size_ / ( vsize + tsize ) );
82 FT_Vector* points = reinterpret_cast<FT_Vector*>(
85 char* tags = reinterpret_cast<char*>(
87 data + size_t( n_points ) * vsize ) );
89 // to reduce the number of invalid outlines that are immediately
90 // rejected in `FT_Outline_Render', limit values to 2^18 pixels
92 for ( short i = 0; i < n_points; i++ )
94 if ( points[i].x == LONG_MIN )
96 else if ( points[i].x < 0 )
97 points[i].x = -( -points[i].x & 0xFFFFFF ) - 1;
99 points[i].x = ( points[i].x & 0xFFFFFF ) + 1;
101 if ( points[i].y == LONG_MIN )
103 else if ( points[i].y < 0 )
104 points[i].y = -( -points[i].y & 0xFFFFFF ) - 1;
106 points[i].y = ( points[i].y & 0xFFFFFF ) + 1;
110 contours[0] = n_points - 1;
115 n_points, // n_points
118 contours, // contours
119 FT_OUTLINE_NONE // flags
122 FT_Outline_Get_Bitmap( library, &outline, &bitmap_mono );
123 FT_Outline_Get_Bitmap( library, &outline, &bitmap_gray );