kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 1 | // Copyright 2017 The PDFium Authors |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame] | 5 | #include "public/cpp/fpdf_scopers.h" |
| 6 | #include "public/fpdf_edit.h" |
| 7 | #include "public/fpdfview.h" |
| 8 | |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 9 | static constexpr size_t kMaxFuzzBytes = 1024 * 1024 * 1024; // 1 GB. |
| 10 | |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame] | 11 | extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 12 | if (size < 2 || size > kMaxFuzzBytes) |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame] | 13 | 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; |
kumarashishg | 826308d | 2023-06-23 13:21:22 +0000 | [diff] [blame] | 21 | ScopedFPDFFont font(FPDFText_LoadFont( |
| 22 | doc.get(), data, static_cast<uint32_t>(size), font_type, cid)); |
Haibo Huang | 49cc930 | 2020-04-27 16:14:24 -0700 | [diff] [blame] | 23 | 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 | } |