2026-06-11 19:19:01 +05:30
|
|
|
|
|
|
|
|
#include "pdfengine/hardened_limits.h"
|
|
|
|
|
#include "pdfengine/pdf_document.hpp"
|
|
|
|
|
|
|
|
|
|
#include <cstddef>
|
|
|
|
|
#include <cstdint>
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
|
|
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
|
|
|
|
|
using namespace pdfengine;
|
|
|
|
|
|
|
|
|
|
if (!limits::documentSizeOk(size)) return 0;
|
|
|
|
|
|
|
|
|
|
std::vector<uint8_t> bytes(data, data + size);
|
|
|
|
|
auto doc = PdfDocument::loadFromMemory(bytes, "");
|
|
|
|
|
if (!doc) return 0;
|
|
|
|
|
PdfDocument& d = **doc;
|
|
|
|
|
|
|
|
|
|
const int pages = d.pageCount();
|
|
|
|
|
if (!limits::pageCountOk(pages)) return 0;
|
|
|
|
|
|
|
|
|
|
(void)d.metadata();
|
|
|
|
|
(void)d.extractOutline();
|
|
|
|
|
|
2026-06-22 15:18:47 +05:30
|
|
|
const int limit = pages < 3 ? pages : 3;
|
2026-06-11 19:19:01 +05:30
|
|
|
for (int i = 0; i < limit; ++i) {
|
|
|
|
|
auto page = d.getPage(i);
|
|
|
|
|
if (!page) continue;
|
|
|
|
|
PdfPage& p = **page;
|
|
|
|
|
|
|
|
|
|
(void)p.render(72);
|
|
|
|
|
(void)p.extractText();
|
|
|
|
|
(void)p.extractAnnotations();
|
|
|
|
|
|
|
|
|
|
auto glyphs = p.orderedGlyphs();
|
|
|
|
|
if (glyphs && !glyphs->empty()) {
|
|
|
|
|
const auto& g = glyphs->front();
|
|
|
|
|
(void)p.hitGlyph(g.x, g.y);
|
|
|
|
|
(void)p.selectRange(g.x, g.y, g.x + 50.0, g.y + 20.0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|