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

Side by Side Diff: third_party/sfntly/fuzzers/subset_font_fuzzer.cc

Issue 2308443002: Make FuzzedDataProvider vend std::strings (Closed)
Patch Set: thestig review Created 4 years, 2 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/WebKit/Source/platform/testing/FuzzedDataProvider.cpp ('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 Chromimum Authors. All rights reserved. 1 // Copyright 2016 The Chromimum 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 <cstdint> 5 #include <cstdint>
6 #include <string>
6 7
7 #include "base/test/fuzzed_data_provider.h" 8 #include "base/test/fuzzed_data_provider.h"
8 #include "third_party/sfntly/src/cpp/src/sample/chromium/font_subsetter.h" 9 #include "third_party/sfntly/src/cpp/src/sample/chromium/font_subsetter.h"
9 10
10 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { 11 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
11 constexpr int kMaxFontNameSize = 128; 12 constexpr int kMaxFontNameSize = 128;
12 constexpr int kMaxFontSize = 50 * 1024 * 1024; 13 constexpr int kMaxFontSize = 50 * 1024 * 1024;
13 base::FuzzedDataProvider fuzzed_data(data, size); 14 base::FuzzedDataProvider fuzzed_data(data, size);
14 15
15 size_t font_name_size = fuzzed_data.ConsumeUint32InRange(0, kMaxFontNameSize); 16 size_t font_name_size = fuzzed_data.ConsumeUint32InRange(0, kMaxFontNameSize);
16 base::StringPiece font_name = fuzzed_data.ConsumeBytes(font_name_size); 17 std::string font_name = fuzzed_data.ConsumeBytes(font_name_size);
17 18
18 size_t font_str_size = fuzzed_data.ConsumeUint32InRange(0, kMaxFontSize); 19 size_t font_str_size = fuzzed_data.ConsumeUint32InRange(0, kMaxFontSize);
19 base::StringPiece font_str = fuzzed_data.ConsumeBytes(font_str_size); 20 std::string font_str = fuzzed_data.ConsumeBytes(font_str_size);
20 const unsigned char* font_data = 21 const unsigned char* font_data =
21 reinterpret_cast<const unsigned char*>(font_str.data()); 22 reinterpret_cast<const unsigned char*>(font_str.data());
22 23
23 base::StringPiece glyph_ids_str = fuzzed_data.ConsumeRemainingBytes(); 24 std::string glyph_ids_str = fuzzed_data.ConsumeRemainingBytes();
24 const unsigned int* glyph_ids = 25 const unsigned int* glyph_ids =
25 reinterpret_cast<const unsigned int*>(glyph_ids_str.data()); 26 reinterpret_cast<const unsigned int*>(glyph_ids_str.data());
26 size_t glyph_ids_size = 27 size_t glyph_ids_size =
27 glyph_ids_str.size() * sizeof(char) / sizeof(unsigned int); 28 glyph_ids_str.size() * sizeof(char) / sizeof(unsigned int);
28 29
29 unsigned char* output = nullptr; 30 unsigned char* output = nullptr;
30 SfntlyWrapper::SubsetFont(font_name.data(), font_data, font_str_size, 31 SfntlyWrapper::SubsetFont(font_name.data(), font_data, font_str_size,
31 glyph_ids, glyph_ids_size, &output); 32 glyph_ids, glyph_ids_size, &output);
32 delete[] output; 33 delete[] output;
33 return 0; 34 return 0;
34 } 35 }
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/testing/FuzzedDataProvider.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698