OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include <cstdint> |
| 6 |
| 7 #include "base/test/fuzzed_data_provider.h" |
| 8 #include "third_party/sfntly/src/cpp/src/sample/chromium/font_subsetter.h" |
| 9 |
| 10 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { |
| 11 constexpr int kMaxFontNameSize = 128; |
| 12 constexpr int kMaxFontSize = 50 * 1024 * 1024; |
| 13 base::FuzzedDataProvider fuzzed_data(data, size); |
| 14 |
| 15 size_t font_name_size = fuzzed_data.ConsumeUint32InRange(0, kMaxFontNameSize); |
| 16 base::StringPiece font_name = fuzzed_data.ConsumeBytes(font_name_size); |
| 17 |
| 18 size_t font_str_size = fuzzed_data.ConsumeUint32InRange(0, kMaxFontSize); |
| 19 base::StringPiece font_str = fuzzed_data.ConsumeBytes(font_str_size); |
| 20 const unsigned char* font_data = |
| 21 reinterpret_cast<const unsigned char*>(font_str.data()); |
| 22 |
| 23 base::StringPiece glyph_ids_str = fuzzed_data.ConsumeRemainingBytes(); |
| 24 const unsigned int* glyph_ids = |
| 25 reinterpret_cast<const unsigned int*>(glyph_ids_str.data()); |
| 26 size_t glyph_ids_size = |
| 27 glyph_ids_str.size() * sizeof(char) / sizeof(unsigned int); |
| 28 |
| 29 unsigned char* output = nullptr; |
| 30 SfntlyWrapper::SubsetFont(font_name.data(), font_data, font_str_size, |
| 31 glyph_ids, glyph_ids_size, &output); |
| 32 delete[] output; |
| 33 return 0; |
| 34 } |
OLD | NEW |