/src/qpdf/fuzz/runlength_fuzzer.cc
Line | Count | Source |
1 | | #include <qpdf/Pl_Discard.hh> |
2 | | #include <qpdf/Pl_RunLength.hh> |
3 | | #include <qpdf/global.hh> |
4 | | |
5 | | #include <iostream> |
6 | | #include <stdexcept> |
7 | | |
8 | | class FuzzHelper |
9 | | { |
10 | | public: |
11 | | FuzzHelper(unsigned char const* data, size_t size) : |
12 | 313k | data(data), |
13 | 313k | size(size) |
14 | 313k | { |
15 | 313k | } |
16 | | |
17 | | void |
18 | | run() |
19 | 208k | { |
20 | 208k | qpdf::global::options::fuzz_mode(true); |
21 | | |
22 | 208k | Pl_Discard discard; |
23 | 208k | Pl_RunLength p("decode", &discard, Pl_RunLength::a_decode); |
24 | 208k | try { |
25 | 208k | p.write(data, size); |
26 | 208k | p.finish(); |
27 | 208k | } catch (std::runtime_error const& e) { |
28 | 139k | std::cerr << "runtime_error: " << e.what() << '\n'; |
29 | 139k | } |
30 | 208k | } |
31 | | |
32 | | private: |
33 | | unsigned char const* data; |
34 | | size_t size; |
35 | | }; |
36 | | |
37 | | extern "C" int |
38 | | LLVMFuzzerTestOneInput(unsigned char const* data, size_t size) |
39 | 313k | { |
40 | 313k | FuzzHelper f(data, size); |
41 | 313k | f.run(); |
42 | 313k | return 0; |
43 | 313k | } |