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

Unified Diff: third_party/hunspell/fuzz/hunspell_fuzzer.cc

Issue 2012443002: [libfuzzer] Add fuzzer for third_party/hunspell with dictionary. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add #include guard and license block to hunspell_fuzzer_dictionary.h. Created 4 years, 7 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
Index: third_party/hunspell/fuzz/hunspell_fuzzer.cc
diff --git a/third_party/hunspell/fuzz/hunspell_fuzzer.cc b/third_party/hunspell/fuzz/hunspell_fuzzer.cc
new file mode 100644
index 0000000000000000000000000000000000000000..9828df9a4406bc7470406852ed9eb48c91694dc7
--- /dev/null
+++ b/third_party/hunspell/fuzz/hunspell_fuzzer.cc
@@ -0,0 +1,34 @@
+// 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/hunspell/src/hunspell/hunspell.hxx"
+
+#include <string>
please use gerrit instead 2016/06/01 17:09:17 This include should be next to <stdint.h>
mmoroz 2016/06/02 10:54:36 Done.
+
+#include "hunspell_fuzzer_dictionary.h"
please use gerrit instead 2016/06/01 17:09:17 All includes should have full path. #include "thi
mmoroz 2016/06/02 10:54:36 Done.
+
+static Hunspell *CreateHunspell() {
please use gerrit instead 2016/06/01 17:09:17 This function is used only once. You should inline
mmoroz 2016/06/02 10:54:36 We disable inlining for fuzzers, so I guess it won
please use gerrit instead 2016/06/02 16:03:50 Sorry, when I said "inline", I meant this: static
mmoroz 2016/06/03 13:07:37 Done.
+ return new Hunspell(
+ reinterpret_cast<const unsigned char*>(kHunspell_Dictionary),
+ sizeof(kHunspell_Dictionary));
+}
+
+// Entry point for LibFuzzer.
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
+ if (!size)
+ return 0;
+
+ static Hunspell *hunspell = CreateHunspell();
+ std::string data_string(reinterpret_cast<const char*>(data), size);
+ hunspell->spell(data_string.c_str());
+
+ char** suggestions = nullptr;
+ int suggetion_length = hunspell->suggest(&suggestions, data_string.c_str());
+ hunspell->free_list(&suggestions, suggetion_length);
+
+ return 0;
+}

Powered by Google App Engine
This is Rietveld 408576698