/src/poppler/qt5/tests/fuzzing/qt_annot_fuzzer.cc
Line | Count | Source |
1 | | #include <cstdint> |
2 | | #include <poppler-qt5.h> |
3 | | #include <QtCore/QBuffer> |
4 | | |
5 | 40.7M | static void dummy_error_function(const QString &, const QVariant &) { } |
6 | | |
7 | | extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) |
8 | 56.2k | { |
9 | 56.2k | Poppler::setDebugErrorFunction(dummy_error_function, QVariant()); |
10 | 56.2k | const QFont font(QStringLiteral("Helvetica"), 20); |
11 | 56.2k | const QColor color = QColor::fromRgb(0xAB, 0xCD, 0xEF); |
12 | | |
13 | 56.2k | QByteArray in_data = QByteArray::fromRawData((const char *)data, size); |
14 | 56.2k | Poppler::Document *doc = Poppler::Document::loadFromData(in_data); |
15 | | |
16 | 56.2k | if (!doc || doc->isLocked()) { |
17 | 10.2k | delete doc; |
18 | 10.2k | return 0; |
19 | 10.2k | } |
20 | | |
21 | 365k | for (int i = 0; i < doc->numPages(); i++) { |
22 | 320k | Poppler::Page *p = doc->page(i); |
23 | 320k | if (!p) { |
24 | 208k | continue; |
25 | 208k | } |
26 | 111k | Poppler::TextAnnotation *ann = new Poppler::TextAnnotation(Poppler::TextAnnotation::InPlace); |
27 | 111k | ann->setTextFont(font); |
28 | 111k | ann->setTextColor(color); |
29 | 111k | ann->setBoundary(QRectF(0.1, 0.1, 0.2, 0.2)); |
30 | 111k | ann->setContents(QString(in_data)); |
31 | 111k | p->addAnnotation(ann); |
32 | | |
33 | 111k | QBuffer buffer; |
34 | 111k | buffer.open(QIODevice::WriteOnly); |
35 | 111k | std::unique_ptr<Poppler::PDFConverter> conv(doc->pdfConverter()); |
36 | 111k | conv->setOutputDevice(&buffer); |
37 | 111k | conv->setPDFOptions(Poppler::PDFConverter::WithChanges); |
38 | 111k | conv->convert(); |
39 | 111k | buffer.close(); |
40 | 111k | delete ann; |
41 | 111k | delete p; |
42 | 111k | } |
43 | | |
44 | 45.9k | delete doc; |
45 | 45.9k | return 0; |
46 | 56.2k | } |