/src/poppler/qt5/tests/fuzzing/qt_textbox_fuzzer.cc
Line | Count | Source |
1 | | #include <cstdint> |
2 | | #include <poppler-qt5.h> |
3 | | #include <QtGui/QImage> |
4 | | #include <QtGui/QPainter> |
5 | | |
6 | 35.4M | static void dummy_error_function(const QString &, const QVariant &) { } |
7 | | |
8 | | extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) |
9 | 74.3k | { |
10 | 74.3k | Poppler::setDebugErrorFunction(dummy_error_function, QVariant()); |
11 | 74.3k | QByteArray in_data = QByteArray::fromRawData((const char *)data, size); |
12 | 74.3k | Poppler::Document *doc = Poppler::Document::loadFromData(in_data); |
13 | 74.3k | if (!doc || doc->isLocked()) { |
14 | 15.5k | delete doc; |
15 | 15.5k | return 0; |
16 | 15.5k | } |
17 | | |
18 | 526k | for (int i = 0; i < doc->numPages(); i++) { |
19 | 467k | Poppler::Page *p = doc->page(i); |
20 | 467k | if (!p) { |
21 | 339k | continue; |
22 | 339k | } |
23 | 128k | QRectF rf = QRectF(0.0, 0.0, 1.0, 1.0); |
24 | 128k | Poppler::TextBox tb(QString(in_data), rf); |
25 | 128k | QImage image = p->renderToImage(72.0, 72.0, -1, -1, -1, -1, Poppler::Page::Rotate0); |
26 | 128k | QPainter painter(&image); |
27 | 128k | painter.drawRect(tb.boundingBox()); |
28 | 128k | delete p; |
29 | 128k | } |
30 | 58.8k | delete doc; |
31 | 58.8k | return 0; |
32 | 74.3k | } |