Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(195)

Unified Diff: testing/libfuzzer/fuzzers/ft_new_memory_face_fuzzer.cc

Issue 1776323002: [libfuzzer] Add fuzzer for FT_New_Memory_Face() from third_party/freetype2. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix the nit. Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « testing/libfuzzer/fuzzers/BUILD.gn ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: testing/libfuzzer/fuzzers/ft_new_memory_face_fuzzer.cc
diff --git a/testing/libfuzzer/fuzzers/ft_new_memory_face_fuzzer.cc b/testing/libfuzzer/fuzzers/ft_new_memory_face_fuzzer.cc
new file mode 100644
index 0000000000000000000000000000000000000000..cac3ef697287c921db7ad388affaf05dae075a84
--- /dev/null
+++ b/testing/libfuzzer/fuzzers/ft_new_memory_face_fuzzer.cc
@@ -0,0 +1,55 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <stddef.h>
+#include <stdint.h>
+
+#include "third_party/freetype2/src/include/ft2build.h"
+#include "third_party/freetype2/src/include/freetype/freetype.h"
+
+
+FT_Error g_init_freetype_error;
+
+
+struct InitFreetype {
+ FT_Library* library_;
+ InitFreetype(FT_Library* library) : library_(library) {
+ g_init_freetype_error = FT_Init_FreeType(library);
+ }
+ ~InitFreetype() {
+ FT_Init_FreeType(library_);
+ }
+};
+
+
+FT_Library g_freetype_library;
+InitFreetype g_init_freetype(&g_freetype_library);
+
+
+// Entry point for LibFuzzer.
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
+ if (g_init_freetype_error)
+ return 0;
+
+ FT_Face face;
+ // Get number of faces in font. Usually 0 for random data.
+ FT_Error error = FT_New_Memory_Face(g_freetype_library, data, size, -1,
+ &face);
+ if (error)
+ return 0;
+
+ // Go through the faces.
+ for (FT_Long face_index = 0; face_index < face->num_faces + 1; ++face_index) {
+ FT_Face temp_face;
+ error = FT_New_Memory_Face(g_freetype_library, data, size, face_index,
+ &temp_face);
+ if (error)
+ break;
+ FT_Done_Face(temp_face);
+ }
+
+ FT_Done_Face(face);
+
+ return 0;
+}
« no previous file with comments | « testing/libfuzzer/fuzzers/BUILD.gn ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698