blob: a02052ae7a5f85e493d34371d3e73c7f5dd7a7b9 [file] [log] [blame]
kumarashishg826308d2023-06-23 13:21:22 +00001// Copyright 2017 The PDFium Authors
Haibo Huang49cc9302020-04-27 16:14:24 -07002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Haibo Huang49cc9302020-04-27 16:14:24 -07005#include "public/cpp/fpdf_scopers.h"
6#include "public/fpdf_edit.h"
7#include "public/fpdfview.h"
8
kumarashishg826308d2023-06-23 13:21:22 +00009static constexpr size_t kMaxFuzzBytes = 1024 * 1024 * 1024; // 1 GB.
10
Haibo Huang49cc9302020-04-27 16:14:24 -070011extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
kumarashishg826308d2023-06-23 13:21:22 +000012 if (size < 2 || size > kMaxFuzzBytes)
Haibo Huang49cc9302020-04-27 16:14:24 -070013 return 0;
14
15 ScopedFPDFDocument doc(FPDF_CreateNewDocument());
16 ScopedFPDFPage page(FPDFPage_New(doc.get(), 0, 612, 792));
17 int font_type = data[0];
18 FPDF_BOOL cid = data[1];
19 data += 2;
20 size -= 2;
kumarashishg826308d2023-06-23 13:21:22 +000021 ScopedFPDFFont font(FPDFText_LoadFont(
22 doc.get(), data, static_cast<uint32_t>(size), font_type, cid));
Haibo Huang49cc9302020-04-27 16:14:24 -070023 if (!font)
24 return 0;
25
26 FPDF_PAGEOBJECT text_object =
27 FPDFPageObj_CreateTextObj(doc.get(), font.get(), 12.0f);
28 FPDFPage_InsertObject(page.get(), text_object);
29 FPDFPage_GenerateContent(page.get());
30 return 0;
31}