xref: /aosp_15_r20/external/pdfium/testing/fuzzers/pdf_cfx_barcode_fuzzer.cc (revision 3ac0a46f773bac49fa9476ec2b1cf3f8da5ec3a4)
1 // Copyright 2017 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 "core/fxcrt/fx_string.h"
6 #include "fxbarcode/cfx_barcode.h"
7 
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)8 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
9   if (size < 2 * sizeof(uint16_t))
10     return 0;
11 
12   BC_TYPE type =
13       static_cast<BC_TYPE>(data[0] % (static_cast<int>(BC_TYPE::kLast) + 1));
14 
15   // Only used one byte, but align with uint16_t for string below.
16   data += sizeof(uint16_t);
17   size -= sizeof(uint16_t);
18 
19   auto barcode = CFX_Barcode::Create(type);
20 
21   // TODO(tsepez): Setup more options from |data|.
22   barcode->SetModuleHeight(300);
23   barcode->SetModuleWidth(420);
24   barcode->SetHeight(298);
25   barcode->SetWidth(418);
26 
27   WideString content = WideString::FromUTF16LE(
28       reinterpret_cast<const uint16_t*>(data), size / sizeof(uint16_t));
29 
30   if (!barcode->Encode(content.AsStringView()))
31     return 0;
32 
33   // TODO(tsepez): Output to device.
34   return 0;
35 }
36