blob: 793d18e76058f11d7f1a999f47dd1543fa5139e6 [file] [log] [blame]
kumarashishg826308d2023-06-23 13:21:22 +00001// Copyright 2016 The PDFium Authors
Haibo Huang49cc9302020-04-27 16:14:24 -07002// 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
12extern "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;
kumarashishg826308d2023-06-23 13:21:22 +000041 while (!decoder->GetScanline(line).empty())
Haibo Huang49cc9302020-04-27 16:14:24 -070042 line++;
43 }
44
45 return 0;
46}