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

Side by Side Diff: third_party/hunspell/fuzz/hunspell_fuzzer.cc

Issue 2223603002: [Hunspell Fuzzer] Restrict fuzzer data to valid UTF8 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Clearly, adding a dependency is HARD. Created 4 years, 3 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 unified diff | Download patch
« no previous file with comments | « third_party/hunspell/fuzz/DEPS ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 #include <string> 7 #include <string>
8 8
9 #include "base/strings/string16.h"
10 #include "base/strings/utf_string_conversions.h"
9 #include "third_party/hunspell/src/hunspell/hunspell.hxx" 11 #include "third_party/hunspell/src/hunspell/hunspell.hxx"
10 #include "third_party/hunspell/fuzz/hunspell_fuzzer_hunspell_dictionary.h" 12 #include "third_party/hunspell/fuzz/hunspell_fuzzer_hunspell_dictionary.h"
11 13
12 // Entry point for LibFuzzer. 14 // Entry point for LibFuzzer.
13 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { 15 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
14 if (!size) 16 if (!size)
15 return 0; 17 return 0;
16 18
17 static Hunspell* hunspell = new Hunspell(kHunspellDictionary, 19 static Hunspell* hunspell = new Hunspell(kHunspellDictionary,
18 sizeof(kHunspellDictionary)); 20 sizeof(kHunspellDictionary));
19 21
20 std::string data_string(reinterpret_cast<const char*>(data), size); 22 std::string data_string(reinterpret_cast<const char*>(data), size);
23
24 // hunspell is not handling invalid UTF8. To avoid that, do the same thing
25 // Chromium does - convert to UTF16, and back to UTF8. Valid UTF8 guaranteed.
26 base::string16 utf16_string = base::UTF8ToUTF16(data_string);
27 data_string = base::UTF16ToUTF8(utf16_string);
28
21 hunspell->spell(data_string.c_str()); 29 hunspell->spell(data_string.c_str());
22 30
23 char** suggestions = nullptr; 31 char** suggestions = nullptr;
24 int suggetion_length = hunspell->suggest(&suggestions, data_string.c_str()); 32 int suggestion_length = hunspell->suggest(&suggestions, data_string.c_str());
25 hunspell->free_list(&suggestions, suggetion_length); 33 hunspell->free_list(&suggestions, suggestion_length);
26 34
27 return 0; 35 return 0;
28 } 36 }
OLDNEW
« no previous file with comments | « third_party/hunspell/fuzz/DEPS ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698