diff options
author | Lei Zhang <thestig@chromium.org> | 2018-10-09 22:10:29 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-10-09 22:10:29 +0000 |
commit | 95860d77fb882317da74ec614ff841fcacdcaa83 (patch) | |
tree | 6ea65f7473d81e909f07afff982c3db3d430076e /testing/fuzzers/pdfium_xfa_fuzzer.cc | |
parent | 51948abf13328b9ebe6574d77dcdf1f99e94f0da (diff) | |
download | pdfium-95860d77fb882317da74ec614ff841fcacdcaa83.tar.xz |
Copy some fuzzer code from Chromium into PDFium.
These came from Chromium's pdf/pdfium/fuzzer directory. The code has
been modified to be buildable in standalone PDFium and modernized.
Change-Id: Ia4ddad4a164f798689af4b9f92d41d635901dccb
Reviewed-on: https://pdfium-review.googlesource.com/c/43530
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Diffstat (limited to 'testing/fuzzers/pdfium_xfa_fuzzer.cc')
-rw-r--r-- | testing/fuzzers/pdfium_xfa_fuzzer.cc | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/testing/fuzzers/pdfium_xfa_fuzzer.cc b/testing/fuzzers/pdfium_xfa_fuzzer.cc new file mode 100644 index 0000000000..f9a69d4166 --- /dev/null +++ b/testing/fuzzers/pdfium_xfa_fuzzer.cc @@ -0,0 +1,31 @@ +// Copyright 2017 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include <stdint.h> + +#include "public/fpdf_formfill.h" +#include "testing/fuzzers/pdfium_fuzzer_helper.h" + +class PDFiumXFAFuzzer : public PDFiumFuzzerHelper { + public: + PDFiumXFAFuzzer() = default; + ~PDFiumXFAFuzzer() override = default; + + int GetFormCallbackVersion() const override { return 2; } + + // Return false if XFA doesn't load as otherwise we're duplicating the work + // done by the non-xfa fuzzer. + bool OnFormFillEnvLoaded(FPDF_DOCUMENT doc) override { + int form_type = FPDF_GetFormType(doc); + if (form_type != FORMTYPE_XFA_FULL && form_type != FORMTYPE_XFA_FOREGROUND) + return false; + return FPDF_LoadXFA(doc); + } +}; + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { + PDFiumXFAFuzzer fuzzer; + fuzzer.RenderPdf(reinterpret_cast<const char*>(data), size); + return 0; +} |