/src/poppler/cpp/tests/fuzzing/doc_fuzzer.cc
Line | Count | Source |
1 | | #include <cstdint> |
2 | | #include <poppler-document.h> |
3 | | #include <poppler-global.h> |
4 | | #include "fuzzer_init.h" |
5 | | |
6 | | #include "FuzzedDataProvider.h" |
7 | | |
8 | | const size_t input_size = 32; |
9 | | const size_t count = 6; |
10 | | |
11 | 10.3M | static void dummy_error_function(const std::string &, void *) { } |
12 | | |
13 | | extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) |
14 | 252 | { |
15 | 252 | initialize_poppler_data_dir(); |
16 | 252 | if (size < input_size * count) { |
17 | 0 | return 0; |
18 | 0 | } |
19 | 252 | poppler::set_debug_error_function(dummy_error_function, nullptr); |
20 | 252 | poppler::document *doc = poppler::document::load_from_raw_data((const char *)data, size); |
21 | 252 | if (!doc || doc->is_locked()) { |
22 | 129 | delete doc; |
23 | 129 | return 0; |
24 | 129 | } |
25 | | |
26 | 123 | FuzzedDataProvider data_provider(data, size); |
27 | 123 | std::string in_auth = data_provider.ConsumeBytesAsString(input_size); |
28 | 123 | std::string in_creat = data_provider.ConsumeBytesAsString(input_size); |
29 | 123 | std::string in_key = data_provider.ConsumeBytesAsString(input_size); |
30 | 123 | std::string in_prod = data_provider.ConsumeBytesAsString(input_size); |
31 | 123 | std::string in_sub = data_provider.ConsumeBytesAsString(input_size); |
32 | 123 | std::string in_title = data_provider.ConsumeBytesAsString(input_size); |
33 | | |
34 | | // Testing both methods for conversion to ustring |
35 | 123 | doc->set_author(poppler::ustring::from_latin1(in_auth)); |
36 | 123 | doc->set_creator(poppler::ustring::from_latin1(in_creat)); |
37 | 123 | doc->set_keywords(poppler::ustring::from_latin1(in_key)); |
38 | 123 | doc->set_producer(poppler::ustring::from_latin1(in_prod)); |
39 | 123 | doc->set_subject(poppler::ustring::from_latin1(in_sub)); |
40 | 123 | doc->set_title(poppler::ustring::from_latin1(in_title)); |
41 | | |
42 | 123 | doc->set_author(poppler::ustring::from_utf8(in_auth.c_str(), -1)); |
43 | 123 | doc->set_creator(poppler::ustring::from_utf8(in_creat.c_str(), -1)); |
44 | 123 | doc->set_keywords(poppler::ustring::from_utf8(in_key.c_str(), -1)); |
45 | 123 | doc->set_producer(poppler::ustring::from_utf8(in_prod.c_str(), -1)); |
46 | 123 | doc->set_subject(poppler::ustring::from_utf8(in_sub.c_str(), -1)); |
47 | 123 | doc->set_title(poppler::ustring::from_utf8(in_title.c_str(), -1)); |
48 | | |
49 | 123 | delete doc; |
50 | 123 | return 0; |
51 | 252 | } |