| 1 |
#include <cstdint> |
| 2 |
#include <poppler-document.h> |
| 3 |
#include <poppler-global.h> |
| 4 |
#include <poppler-page.h> |
| 5 |
#include <poppler-page-renderer.h> |
| 6 |
|
| 7 |
#include "FuzzedDataProvider.h" |
| 8 |
|
| 9 |
const size_t input_size = 32; |
| 10 |
|
| 11 |
static void dummy_error_function(const std::string &, void *) { } |
| 12 |
|
| 13 |
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) |
| 14 |
{ |
| 15 |
if (size < input_size) { |
| 16 |
return 0; |
| 17 |
} |
| 18 |
poppler::set_debug_error_function(dummy_error_function, nullptr); |
| 19 |
|
| 20 |
poppler::document *doc = poppler::document::load_from_raw_data((const char *)data, size); |
| 21 |
if (!doc || doc->is_locked()) { |
| 22 |
delete doc; |
| 23 |
return 0; |
| 24 |
} |
| 25 |
|
| 26 |
poppler::page_renderer r; |
| 27 |
FuzzedDataProvider data_provider(data, size); |
| 28 |
std::string in_text = data_provider.ConsumeBytesAsString(input_size); |
| 29 |
for (int i = 0; i < doc->pages(); i++) { |
| 30 |
poppler::page *p = doc->create_page(i); |
| 31 |
if (!p) { |
| 32 |
continue; |
| 33 |
} |
| 34 |
poppler::rectf rect = p->page_rect(); |
| 35 |
poppler::ustring text = poppler::ustring::from_utf8(in_text.c_str(), -1); |
| 36 |
p->search(text, rect, poppler::page::search_from_top, poppler::case_insensitive, poppler::rotate_0); |
| 37 |
r.render_page(p); |
| 38 |
delete p; |
| 39 |
} |
| 40 |
|
| 41 |
delete doc; |
| 42 |
return 0; |
| 43 |
} |