1 // Copyright 2017 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include <stdint.h> 6 7 #include "public/fpdf_formfill.h" 8 #include "testing/fuzzers/pdfium_fuzzer_helper.h" 9 10 class PDFiumXFAFuzzer : public PDFiumFuzzerHelper { 11 public: 12 PDFiumXFAFuzzer() = default; 13 ~PDFiumXFAFuzzer() override = default; 14 GetFormCallbackVersion() const15 int GetFormCallbackVersion() const override { return 2; } 16 17 // Return false if XFA doesn't load as otherwise we're duplicating the work 18 // done by the non-xfa fuzzer. OnFormFillEnvLoaded(FPDF_DOCUMENT doc)19 bool OnFormFillEnvLoaded(FPDF_DOCUMENT doc) override { 20 int form_type = FPDF_GetFormType(doc); 21 if (form_type != FORMTYPE_XFA_FULL && form_type != FORMTYPE_XFA_FOREGROUND) 22 return false; 23 return FPDF_LoadXFA(doc); 24 } 25 }; 26 LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)27extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { 28 PDFiumXFAFuzzer fuzzer; 29 fuzzer.RenderPdf(reinterpret_cast<const char*>(data), size); 30 return 0; 31 } 32