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