Tom Sepez | 5628fd7 | 2017-04-27 14:58:53 -0700 | [diff] [blame] | 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 | |
Tom Sepez | 5628fd7 | 2017-04-27 14:58:53 -0700 | [diff] [blame] | 5 | #include "core/fxcrt/fx_string.h" |
Tom Sepez | ae5d92a | 2020-01-07 23:41:49 +0000 | [diff] [blame] | 6 | #include "fxbarcode/cfx_barcode.h" |
Tom Sepez | 5628fd7 | 2017-04-27 14:58:53 -0700 | [diff] [blame] | 7 | |
| 8 | extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { |
Tom Sepez | e5f528a | 2018-11-28 00:54:47 +0000 | [diff] [blame] | 9 | if (size < 2 * sizeof(uint16_t)) |
Tom Sepez | 5628fd7 | 2017-04-27 14:58:53 -0700 | [diff] [blame] | 10 | return 0; |
| 11 | |
Lei Zhang | fab1c17 | 2019-01-25 23:08:53 +0000 | [diff] [blame] | 12 | BC_TYPE type = static_cast<BC_TYPE>(data[0] % (BC_LAST + 1)); |
Tom Sepez | 5628fd7 | 2017-04-27 14:58:53 -0700 | [diff] [blame] | 13 | |
Tom Sepez | e5f528a | 2018-11-28 00:54:47 +0000 | [diff] [blame] | 14 | // Only used one byte, but align with uint16_t for string below. |
| 15 | data += sizeof(uint16_t); |
| 16 | size -= sizeof(uint16_t); |
Tom Sepez | 5628fd7 | 2017-04-27 14:58:53 -0700 | [diff] [blame] | 17 | |
Ryan Harrison | 4b9d698 | 2018-01-26 17:11:51 +0000 | [diff] [blame] | 18 | auto barcode = CFX_Barcode::Create(type); |
Tom Sepez | 5628fd7 | 2017-04-27 14:58:53 -0700 | [diff] [blame] | 19 | |
| 20 | // TODO(tsepez): Setup more options from |data|. |
Ryan Harrison | 4b9d698 | 2018-01-26 17:11:51 +0000 | [diff] [blame] | 21 | barcode->SetModuleHeight(300); |
| 22 | barcode->SetModuleWidth(420); |
| 23 | barcode->SetHeight(298); |
| 24 | barcode->SetWidth(418); |
Tom Sepez | 5628fd7 | 2017-04-27 14:58:53 -0700 | [diff] [blame] | 25 | |
Tom Sepez | e5f528a | 2018-11-28 00:54:47 +0000 | [diff] [blame] | 26 | WideString content = WideString::FromUTF16LE( |
| 27 | reinterpret_cast<const uint16_t*>(data), size / sizeof(uint16_t)); |
Tom Sepez | 5628fd7 | 2017-04-27 14:58:53 -0700 | [diff] [blame] | 28 | |
Tom Sepez | e5f528a | 2018-11-28 00:54:47 +0000 | [diff] [blame] | 29 | if (!barcode->Encode(content.AsStringView())) |
Tom Sepez | 5628fd7 | 2017-04-27 14:58:53 -0700 | [diff] [blame] | 30 | return 0; |
| 31 | |
| 32 | // TODO(tsepez): Output to device. |
| 33 | return 0; |
| 34 | } |