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