1 // Copyright 2021 The PDFium Authors 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 <fuzzer/FuzzedDataProvider.h> 6 7 #include <memory> 8 #include <utility> 9 #include <vector> 10 11 #include "core/fpdfapi/font/cpdf_tounicodemap.h" 12 #include "core/fpdfapi/parser/cpdf_stream.h" 13 #include "core/fxcrt/retain_ptr.h" 14 LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)15extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { 16 static constexpr size_t kParameterSize = sizeof(uint32_t) + sizeof(wchar_t); 17 if (size <= kParameterSize) 18 return 0; 19 20 // Limit data size to prevent fuzzer timeout. 21 static constexpr size_t kMaxDataSize = 256 * 1024; 22 if (size > kParameterSize + kMaxDataSize) 23 return 0; 24 25 FuzzedDataProvider data_provider(data, size); 26 uint32_t charcode_to_lookup = data_provider.ConsumeIntegral<uint32_t>(); 27 wchar_t char_for_reverse_lookup = data_provider.ConsumeIntegral<wchar_t>(); 28 29 std::vector<uint8_t> remaining = 30 data_provider.ConsumeRemainingBytes<uint8_t>(); 31 auto stream = pdfium::MakeRetain<CPDF_Stream>(); 32 stream->SetData(remaining); 33 34 auto to_unicode_map = std::make_unique<CPDF_ToUnicodeMap>(std::move(stream)); 35 to_unicode_map->Lookup(charcode_to_lookup); 36 to_unicode_map->ReverseLookup(char_for_reverse_lookup); 37 return 0; 38 } 39