kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 1 | // Copyright 2016 The PDFium Authors |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame] | 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 <cstdint> |
| 6 | #include <memory> |
| 7 | |
| 8 | #include "core/fxcodec/fax/faxmodule.h" |
| 9 | #include "core/fxcodec/scanlinedecoder.h" |
| 10 | #include "testing/fuzzers/pdfium_fuzzer_util.h" |
| 11 | |
| 12 | extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { |
| 13 | static constexpr size_t kParameterSize = 21; |
| 14 | if (size < kParameterSize) |
| 15 | return 0; |
| 16 | |
| 17 | // Limit data size to prevent fuzzer timeout. |
| 18 | static constexpr size_t kMaxDataSize = 256 * 1024; |
| 19 | if (size > kParameterSize + kMaxDataSize) |
| 20 | return 0; |
| 21 | |
| 22 | int width = GetInteger(data); |
| 23 | int height = GetInteger(data + 4); |
| 24 | int K = GetInteger(data + 8); |
| 25 | int Columns = GetInteger(data + 12); |
| 26 | int Rows = GetInteger(data + 16); |
| 27 | bool EndOfLine = !(data[20] & 0x01); |
| 28 | bool ByteAlign = !(data[20] & 0x02); |
| 29 | // This controls if fxcodec::FaxDecoder::InvertBuffer() gets called. |
| 30 | // The method is not interesting, and calling it doubles the runtime. |
| 31 | const bool kBlackIs1 = false; |
| 32 | data += kParameterSize; |
| 33 | size -= kParameterSize; |
| 34 | |
| 35 | std::unique_ptr<ScanlineDecoder> decoder = |
| 36 | FaxModule::CreateDecoder({data, size}, width, height, K, EndOfLine, |
| 37 | ByteAlign, kBlackIs1, Columns, Rows); |
| 38 | |
| 39 | if (decoder) { |
| 40 | int line = 0; |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 41 | while (!decoder->GetScanline(line).empty()) |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame] | 42 | line++; |
| 43 | } |
| 44 | |
| 45 | return 0; |
| 46 | } |