Debian Codegraph @

qt5/tests/fuzzing/qt_textbox_fuzzer.cc

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