diff options
author | Jay Berkenbilt <ejb@ql.org> | 2019-06-23 20:31:35 +0200 |
---|---|---|
committer | Jay Berkenbilt <ejb@ql.org> | 2019-06-23 21:37:21 +0200 |
commit | 0ae344d002755d1f218fe4fbd818a814bc3ebdbc (patch) | |
tree | a4a9205045c43caaf51e7ceccd5edb222c8af657 /fuzz/runlength_fuzzer.cc | |
parent | 43ff34b49c55f03d8613e3cefd405d3c64dc354a (diff) | |
download | qpdf-0ae344d002755d1f218fe4fbd818a814bc3ebdbc.tar.zst |
Add fuzzers to exercise specific pipeline classes
Diffstat (limited to 'fuzz/runlength_fuzzer.cc')
-rw-r--r-- | fuzz/runlength_fuzzer.cc | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/fuzz/runlength_fuzzer.cc b/fuzz/runlength_fuzzer.cc new file mode 100644 index 00000000..bacd3dd8 --- /dev/null +++ b/fuzz/runlength_fuzzer.cc @@ -0,0 +1,52 @@ +#include <qpdf/Pl_Discard.hh> +#include <qpdf/Pl_RunLength.hh> +#include <iostream> +#include <stdexcept> + +class FuzzHelper +{ + public: + FuzzHelper(unsigned char const* data, size_t size); + void run(); + + private: + void doChecks(); + + unsigned char const* data; + size_t size; +}; + +FuzzHelper::FuzzHelper(unsigned char const* data, size_t size) : + data(data), + size(size) +{ +} + +void +FuzzHelper::doChecks() +{ + Pl_Discard discard; + Pl_RunLength p("decode", &discard, Pl_RunLength::a_decode); + p.write(const_cast<unsigned char*>(data), size); + p.finish(); +} + +void +FuzzHelper::run() +{ + try + { + doChecks(); + } + catch (std::runtime_error const& e) + { + std::cerr << "runtime_error: " << e.what() << std::endl; + } +} + +extern "C" int LLVMFuzzerTestOneInput(unsigned char const* data, size_t size) +{ + FuzzHelper f(data, size); + f.run(); + return 0; +} |