/src/qpdf/fuzz/dct_fuzzer.cc
Line | Count | Source |
1 | | #include <qpdf/Pl_DCT.hh> |
2 | | #include <qpdf/Pl_Discard.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 | 7.72k | data(data), |
13 | 7.72k | size(size) |
14 | 7.72k | { |
15 | 7.72k | } |
16 | | |
17 | | void |
18 | | run() |
19 | 7.72k | { |
20 | 7.72k | qpdf::global::options::fuzz_mode(true); |
21 | | |
22 | 7.72k | Pl_Discard discard; |
23 | 7.72k | Pl_DCT p("decode", &discard); |
24 | 7.72k | try { |
25 | 7.72k | p.write(data, size); |
26 | 7.72k | p.finish(); |
27 | 7.72k | } catch (std::runtime_error const& e) { |
28 | 6.98k | std::cerr << "runtime_error: " << e.what() << '\n'; |
29 | 6.98k | } |
30 | 7.72k | } |
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 | 7.72k | { |
40 | 7.72k | #ifndef _WIN32 |
41 | | // Used by jpeg library to work around false positives in memory |
42 | | // sanitizer. |
43 | 7.72k | setenv("JSIMD_FORCENONE", "1", 1); |
44 | 7.72k | #endif |
45 | 7.72k | FuzzHelper f(data, size); |
46 | 7.72k | f.run(); |
47 | 7.72k | return 0; |
48 | 7.72k | } |