/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 | 890k | static void dummy_error_function(const QString &, const QVariant &) { } |
7 | | |
8 | | extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) |
9 | 61.0k | { |
10 | 61.0k | Poppler::setDebugErrorFunction(dummy_error_function, QVariant()); |
11 | 61.0k | QByteArray in_data = QByteArray::fromRawData((const char *)data, size); |
12 | 61.0k | Poppler::Document *doc = Poppler::Document::loadFromData(in_data); |
13 | 61.0k | if (!doc || doc->isLocked()) { |
14 | 12.4k | delete doc; |
15 | 12.4k | return 0; |
16 | 12.4k | } |
17 | | |
18 | 415k | for (int i = 0; i < doc->numPages(); i++) { |
19 | 367k | Poppler::Page *p = doc->page(i); |
20 | 367k | if (!p) { |
21 | 251k | continue; |
22 | 251k | } |
23 | 115k | QRectF rf = QRectF(0.0, 0.0, 1.0, 1.0); |
24 | 115k | Poppler::TextBox tb(QString(in_data), rf); |
25 | 115k | QImage image = p->renderToImage(72.0, 72.0, -1, -1, -1, -1, Poppler::Page::Rotate0); |
26 | 115k | QPainter painter(&image); |
27 | 115k | painter.drawRect(tb.boundingBox()); |
28 | 115k | delete p; |
29 | 115k | } |
30 | 48.5k | delete doc; |
31 | 48.5k | return 0; |
32 | 61.0k | } |