Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include <stddef.h> | |
| 6 #include <stdint.h> | |
| 7 | |
| 8 #include "third_party/freetype2/src/include/ft2build.h" | |
| 9 #include "third_party/freetype2/src/include/freetype/freetype.h" | |
| 10 | |
| 11 | |
| 12 FT_Error g_init_freetype_result; | |
|
inferno
2016/03/09 17:16:43
nit: s/g_init_freetype_result/g_init_freetype_erro
mmoroz
2016/03/10 10:12:55
Done.
| |
| 13 | |
| 14 | |
| 15 struct InitFreetype { | |
| 16 FT_Library* library_; | |
| 17 InitFreetype(FT_Library* library) : library_(library) { | |
| 18 g_init_freetype_result = FT_Init_FreeType(library); | |
| 19 } | |
| 20 ~InitFreetype() { | |
| 21 FT_Init_FreeType(library_); | |
| 22 } | |
| 23 }; | |
| 24 | |
| 25 | |
| 26 FT_Library g_freetype_library; | |
| 27 InitFreetype g_init_freetype(&g_freetype_library); | |
| 28 | |
| 29 | |
| 30 // Entry point for LibFuzzer. | |
| 31 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { | |
|
bungeman-chromium
2016/03/09 18:34:35
This already exists better at https://chromium.goo
| |
| 32 if (g_init_freetype_result) | |
| 33 return 0; | |
| 34 | |
| 35 FT_Face face; | |
| 36 // Get number of faces in font. Usually 0 for random data. | |
| 37 FT_Error error = FT_New_Memory_Face(g_freetype_library, data, size, -1, | |
| 38 &face); | |
| 39 if (error) | |
| 40 return 0; | |
| 41 | |
| 42 // Go through the faces. | |
| 43 for (FT_Long face_index = 0; face_index < face->num_faces + 1; ++face_index) { | |
| 44 FT_Face temp_face; | |
| 45 error = FT_New_Memory_Face(g_freetype_library, data, size, face_index, | |
| 46 &temp_face); | |
| 47 if (error) | |
| 48 break; | |
| 49 FT_Done_Face(temp_face); | |
| 50 } | |
| 51 | |
| 52 FT_Done_Face(face); | |
| 53 | |
| 54 return 0; | |
| 55 } | |
| OLD | NEW |