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