blob: 2fbed3ed98678090a606bac37280368c9a208814 [file] [log] [blame]
Tom Sepez5628fd72017-04-27 14:58:53 -07001// 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
Tom Sepez5628fd72017-04-27 14:58:53 -07005#include "core/fxcrt/fx_string.h"
Tom Sepezae5d92a2020-01-07 23:41:49 +00006#include "fxbarcode/cfx_barcode.h"
Tom Sepez5628fd72017-04-27 14:58:53 -07007
8extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
Tom Sepeze5f528a2018-11-28 00:54:47 +00009 if (size < 2 * sizeof(uint16_t))
Tom Sepez5628fd72017-04-27 14:58:53 -070010 return 0;
11
Lei Zhangfab1c172019-01-25 23:08:53 +000012 BC_TYPE type = static_cast<BC_TYPE>(data[0] % (BC_LAST + 1));
Tom Sepez5628fd72017-04-27 14:58:53 -070013
Tom Sepeze5f528a2018-11-28 00:54:47 +000014 // Only used one byte, but align with uint16_t for string below.
15 data += sizeof(uint16_t);
16 size -= sizeof(uint16_t);
Tom Sepez5628fd72017-04-27 14:58:53 -070017
Ryan Harrison4b9d6982018-01-26 17:11:51 +000018 auto barcode = CFX_Barcode::Create(type);
Tom Sepez5628fd72017-04-27 14:58:53 -070019
20 // TODO(tsepez): Setup more options from |data|.
Ryan Harrison4b9d6982018-01-26 17:11:51 +000021 barcode->SetModuleHeight(300);
22 barcode->SetModuleWidth(420);
23 barcode->SetHeight(298);
24 barcode->SetWidth(418);
Tom Sepez5628fd72017-04-27 14:58:53 -070025
Tom Sepeze5f528a2018-11-28 00:54:47 +000026 WideString content = WideString::FromUTF16LE(
27 reinterpret_cast<const uint16_t*>(data), size / sizeof(uint16_t));
Tom Sepez5628fd72017-04-27 14:58:53 -070028
Tom Sepeze5f528a2018-11-28 00:54:47 +000029 if (!barcode->Encode(content.AsStringView()))
Tom Sepez5628fd72017-04-27 14:58:53 -070030 return 0;
31
32 // TODO(tsepez): Output to device.
33 return 0;
34}