/src/qpdf/fuzz/flate_fuzzer.cc
Line | Count | Source |
1 | | #include <qpdf/Pl_Discard.hh> |
2 | | #include <qpdf/Pl_Flate.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 | 2.25k | data(data), |
13 | 2.25k | size(size) |
14 | 2.25k | { |
15 | 2.25k | } |
16 | | |
17 | | void |
18 | | run() |
19 | 2.25k | { |
20 | 2.25k | qpdf::global::options::fuzz_mode(true); |
21 | | |
22 | 2.25k | Pl_Discard discard; |
23 | 2.25k | Pl_Flate p("decode", &discard, Pl_Flate::a_deflate); |
24 | 2.25k | try { |
25 | 2.25k | p.write(data, size); |
26 | 2.25k | p.finish(); |
27 | 2.25k | } catch (std::runtime_error const& e) { |
28 | 0 | std::cerr << "runtime_error: " << e.what() << '\n'; |
29 | 0 | } |
30 | 2.25k | } |
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 | 2.25k | { |
40 | 2.25k | FuzzHelper f(data, size); |
41 | 2.25k | f.run(); |
42 | 2.25k | return 0; |
43 | 2.25k | } |