summaryrefslogtreecommitdiff
path: root/testing/libfuzzer
diff options
context:
space:
mode:
authorthestig <thestig@chromium.org>2016-11-08 12:59:30 -0800
committerCommit bot <commit-bot@chromium.org>2016-11-08 12:59:30 -0800
commit62114cf3d85ee9149b270e02935c98395567f45e (patch)
treebd5a8e1dcaeb47e53c033c30c44f9f2e33bb3dbc /testing/libfuzzer
parentc59fa8895fa6fa8428b9b278eee6f05478ab8f56 (diff)
downloadpdfium-62114cf3d85ee9149b270e02935c98395567f45e.tar.xz
Compile fuzzer sources in standalone builds. (try 2)
- Add a template for fuzzers to remove redundancy. - Sort fuzzers in alphabetical order. Previous attempt: https://codereview.chromium.org/2480043002/ Review-Url: https://codereview.chromium.org/2481933003
Diffstat (limited to 'testing/libfuzzer')
-rw-r--r--testing/libfuzzer/BUILD.gn225
-rw-r--r--testing/libfuzzer/pdf_fm2js_fuzzer.cc8
-rw-r--r--testing/libfuzzer/pdf_xml_fuzzer.cc12
-rw-r--r--testing/libfuzzer/xfa_codec_fuzzer.h2
4 files changed, 62 insertions, 185 deletions
diff --git a/testing/libfuzzer/BUILD.gn b/testing/libfuzzer/BUILD.gn
index e89918b05f..2b9915d322 100644
--- a/testing/libfuzzer/BUILD.gn
+++ b/testing/libfuzzer/BUILD.gn
@@ -5,7 +5,7 @@
import("../../pdfium.gni")
config("libfuzzer_config") {
- configs = [ "//third_party/pdfium:pdfium_core_config" ]
+ configs = [ "../..:pdfium_core_config" ]
defines = [
"PNG_PREFIX",
@@ -20,256 +20,129 @@ config("libfuzzer_config") {
}
}
-if (pdf_enable_xfa) {
- source_set("pdf_fm2js_fuzzer") {
- testonly = true
- sources = [
- "pdf_fm2js_fuzzer.cc",
- ]
+group("libfuzzer") {
+}
+
+template("pdfium_fuzzer") {
+ source_set(target_name) {
+ sources = invoker.sources
deps = [
- "//third_party/pdfium:pdfium",
+ "../..:pdfium",
]
- configs -= [ "//build/config/compiler:chromium_code" ]
- configs += [
- "//build/config/compiler:no_chromium_code",
- ":libfuzzer_config",
- ]
- }
- source_set("pdf_xml_fuzzer") {
testonly = true
- sources = [
- "pdf_xml_fuzzer.cc",
- ]
- deps = [
- "//third_party/pdfium:pdfium",
- ]
configs -= [ "//build/config/compiler:chromium_code" ]
configs += [
"//build/config/compiler:no_chromium_code",
":libfuzzer_config",
]
}
- source_set("pdf_cfx_saxreader_fuzzer") {
- testonly = true
+}
+
+if (pdf_enable_xfa) {
+ pdfium_fuzzer("pdf_cfx_saxreader_fuzzer") {
sources = [
"pdf_cfx_saxreader_fuzzer.cc",
]
- deps = [
- "//third_party/pdfium:pdfium",
- ]
- configs -= [ "//build/config/compiler:chromium_code" ]
- configs += [
- "//build/config/compiler:no_chromium_code",
- ":libfuzzer_config",
- ]
}
- source_set("pdf_codec_png_fuzzer") {
- testonly = true
+
+ pdfium_fuzzer("pdf_codec_bmp_fuzzer") {
sources = [
- "pdf_codec_png_fuzzer.cc",
+ "pdf_codec_bmp_fuzzer.cc",
"xfa_codec_fuzzer.h",
]
- deps = [
- "//third_party/pdfium:pdfium",
- ]
- configs -= [ "//build/config/compiler:chromium_code" ]
- configs += [
- "//build/config/compiler:no_chromium_code",
- ":libfuzzer_config",
- ]
}
- source_set("pdf_codec_jpeg_fuzzer") {
- testonly = true
+
+ pdfium_fuzzer("pdf_codec_gif_fuzzer") {
sources = [
- "pdf_codec_jpeg_fuzzer.cc",
+ "pdf_codec_gif_fuzzer.cc",
"xfa_codec_fuzzer.h",
]
- deps = [
- "//third_party/pdfium:pdfium",
- ]
- configs -= [ "//build/config/compiler:chromium_code" ]
- configs += [
- "//build/config/compiler:no_chromium_code",
- ":libfuzzer_config",
- ]
}
- source_set("pdf_codec_gif_fuzzer") {
- testonly = true
+
+ pdfium_fuzzer("pdf_codec_jpeg_fuzzer") {
sources = [
- "pdf_codec_gif_fuzzer.cc",
+ "pdf_codec_jpeg_fuzzer.cc",
"xfa_codec_fuzzer.h",
]
- deps = [
- "//third_party/pdfium:pdfium",
- ]
- configs -= [ "//build/config/compiler:chromium_code" ]
- configs += [
- "//build/config/compiler:no_chromium_code",
- ":libfuzzer_config",
- ]
}
- source_set("pdf_codec_bmp_fuzzer") {
- testonly = true
+
+ pdfium_fuzzer("pdf_codec_png_fuzzer") {
sources = [
- "pdf_codec_bmp_fuzzer.cc",
+ "pdf_codec_png_fuzzer.cc",
"xfa_codec_fuzzer.h",
]
- deps = [
- "//third_party/pdfium:pdfium",
- ]
- configs -= [ "//build/config/compiler:chromium_code" ]
- configs += [
- "//build/config/compiler:no_chromium_code",
- ":libfuzzer_config",
- ]
}
- source_set("pdf_codec_tiff_fuzzer") {
- testonly = true
+
+ pdfium_fuzzer("pdf_codec_tiff_fuzzer") {
sources = [
"pdf_codec_tiff_fuzzer.cc",
"xfa_codec_fuzzer.h",
]
- deps = [
- "//third_party/pdfium:pdfium",
- ]
- configs -= [ "//build/config/compiler:chromium_code" ]
- configs += [
- "//build/config/compiler:no_chromium_code",
- ":libfuzzer_config",
- ]
}
- source_set("pdf_css_fuzzer") {
- testonly = true
+
+ pdfium_fuzzer("pdf_css_fuzzer") {
sources = [
"pdf_css_fuzzer.cc",
]
- deps = [
- "//third_party/pdfium:pdfium",
+ }
+
+ pdfium_fuzzer("pdf_fm2js_fuzzer") {
+ sources = [
+ "pdf_fm2js_fuzzer.cc",
]
- configs -= [ "//build/config/compiler:chromium_code" ]
- configs += [
- "//build/config/compiler:no_chromium_code",
- ":libfuzzer_config",
+ }
+
+ pdfium_fuzzer("pdf_xml_fuzzer") {
+ sources = [
+ "pdf_xml_fuzzer.cc",
]
}
}
-source_set("pdf_cmap_fuzzer") {
- testonly = true
+pdfium_fuzzer("pdf_cmap_fuzzer") {
sources = [
"pdf_cmap_fuzzer.cc",
]
- deps = [
- "//third_party/pdfium:pdfium",
- ]
- configs -= [ "//build/config/compiler:chromium_code" ]
- configs += [
- "//build/config/compiler:no_chromium_code",
- ":libfuzzer_config",
- ]
}
-source_set("pdf_codec_fax_fuzzer") {
- testonly = true
+pdfium_fuzzer("pdf_codec_fax_fuzzer") {
sources = [
"pdf_codec_fax_fuzzer.cc",
]
- deps = [
- "//third_party/pdfium:pdfium",
- ]
- configs -= [ "//build/config/compiler:chromium_code" ]
- configs += [
- "//build/config/compiler:no_chromium_code",
- ":libfuzzer_config",
- ]
}
-source_set("pdf_codec_icc_fuzzer") {
- testonly = true
+pdfium_fuzzer("pdf_codec_icc_fuzzer") {
sources = [
"pdf_codec_icc_fuzzer.cc",
]
- deps = [
- "//third_party/pdfium:pdfium",
- ]
- configs -= [ "//build/config/compiler:chromium_code" ]
- configs += [
- "//build/config/compiler:no_chromium_code",
- ":libfuzzer_config",
- ]
}
-source_set("pdf_codec_jbig2_fuzzer") {
- testonly = true
+pdfium_fuzzer("pdf_codec_jbig2_fuzzer") {
sources = [
"pdf_codec_jbig2_fuzzer.cc",
]
- deps = [
- "//third_party/pdfium:pdfium",
- ]
- configs -= [ "//build/config/compiler:chromium_code" ]
- configs += [
- "//build/config/compiler:no_chromium_code",
- ":libfuzzer_config",
- ]
}
-source_set("pdf_jpx_fuzzer") {
- testonly = true
+pdfium_fuzzer("pdf_hint_table_fuzzer") {
sources = [
- "pdf_jpx_fuzzer.cc",
- ]
- deps = [
- "//third_party/pdfium:pdfium",
- ]
- configs -= [ "//build/config/compiler:chromium_code" ]
- configs += [
- "//build/config/compiler:no_chromium_code",
- ":libfuzzer_config",
+ "pdf_hint_table_fuzzer.cc",
]
}
-source_set("pdf_psengine_fuzzer") {
- testonly = true
+pdfium_fuzzer("pdf_jpx_fuzzer") {
sources = [
- "pdf_psengine_fuzzer.cc",
- ]
- deps = [
- "//third_party/pdfium:pdfium",
- ]
- configs -= [ "//build/config/compiler:chromium_code" ]
- configs += [
- "//build/config/compiler:no_chromium_code",
- ":libfuzzer_config",
+ "pdf_jpx_fuzzer.cc",
]
}
-source_set("pdf_hint_table_fuzzer") {
- testonly = true
+pdfium_fuzzer("pdf_psengine_fuzzer") {
sources = [
- "pdf_hint_table_fuzzer.cc",
- ]
- deps = [
- "//third_party/pdfium:pdfium",
- ]
- configs -= [ "//build/config/compiler:chromium_code" ]
- configs += [
- "//build/config/compiler:no_chromium_code",
- ":libfuzzer_config",
+ "pdf_psengine_fuzzer.cc",
]
}
-source_set("pdf_streamparser_fuzzer") {
- testonly = true
+pdfium_fuzzer("pdf_streamparser_fuzzer") {
sources = [
"pdf_streamparser_fuzzer.cc",
]
- deps = [
- "//third_party/pdfium:pdfium",
- ]
- configs -= [ "//build/config/compiler:chromium_code" ]
- configs += [
- "//build/config/compiler:no_chromium_code",
- ":libfuzzer_config",
- ]
}
diff --git a/testing/libfuzzer/pdf_fm2js_fuzzer.cc b/testing/libfuzzer/pdf_fm2js_fuzzer.cc
index 3e3bfae0d4..ced5e18399 100644
--- a/testing/libfuzzer/pdf_fm2js_fuzzer.cc
+++ b/testing/libfuzzer/pdf_fm2js_fuzzer.cc
@@ -6,15 +6,17 @@
#include <cstdint>
#include "core/fxcrt/fx_basic.h"
+#include "core/fxcrt/fx_safe_types.h"
#include "core/fxcrt/fx_string.h"
#include "xfa/fxfa/fm2js/xfa_program.h"
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
- if (size > std::numeric_limits<FX_STRSIZE>::max())
+ FX_SAFE_STRSIZE safe_size = size;
+ if (!safe_size.IsValid())
return 0;
- CFX_WideString input = CFX_WideString::FromUTF8(
- CFX_ByteStringC(data, static_cast<FX_STRSIZE>(size)));
+ CFX_WideString input =
+ CFX_WideString::FromUTF8(CFX_ByteStringC(data, safe_size.ValueOrDie()));
CXFA_FMProgram program;
if (program.Init(input.AsStringC()) || program.ParseProgram())
return 0;
diff --git a/testing/libfuzzer/pdf_xml_fuzzer.cc b/testing/libfuzzer/pdf_xml_fuzzer.cc
index 7bd0b66b37..91b4d6026c 100644
--- a/testing/libfuzzer/pdf_xml_fuzzer.cc
+++ b/testing/libfuzzer/pdf_xml_fuzzer.cc
@@ -4,11 +4,12 @@
#include <cstddef>
#include <cstdint>
-#include <limits>
#include <memory>
#include "core/fxcrt/fx_basic.h"
+#include "core/fxcrt/fx_safe_types.h"
#include "core/fxcrt/fx_system.h"
+#include "third_party/base/ptr_util.h"
#include "xfa/fde/xml/fde_xml_imp.h"
#include "xfa/fxfa/parser/cxfa_xml_parser.h"
#include "xfa/fxfa/parser/cxfa_widetextread.h"
@@ -45,17 +46,18 @@ CFDE_XMLNode* XFA_FDEExtension_GetDocumentNode(
} // namespace
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
- if (size > std::numeric_limits<FX_STRSIZE>::max())
+ FX_SAFE_STRSIZE safe_size = size;
+ if (!safe_size.IsValid())
return 0;
- CFX_WideString input = CFX_WideString::FromUTF8(
- CFX_ByteStringC(data, static_cast<FX_STRSIZE>(size)));
+ CFX_WideString input =
+ CFX_WideString::FromUTF8(CFX_ByteStringC(data, safe_size.ValueOrDie()));
std::unique_ptr<IFX_Stream, ReleaseDeleter<IFX_Stream>> stream(
new CXFA_WideTextRead(input));
if (!stream)
return 0;
- std::unique_ptr<CFDE_XMLDoc> doc(new CFDE_XMLDoc);
+ std::unique_ptr<CFDE_XMLDoc> doc = pdfium::MakeUnique<CFDE_XMLDoc>();
std::unique_ptr<CFDE_XMLParser, ReleaseDeleter<CFDE_XMLParser>> parser(
new CXFA_XMLParser(doc->GetRoot(), stream.get()));
diff --git a/testing/libfuzzer/xfa_codec_fuzzer.h b/testing/libfuzzer/xfa_codec_fuzzer.h
index bf8f985f34..4281db0ac9 100644
--- a/testing/libfuzzer/xfa_codec_fuzzer.h
+++ b/testing/libfuzzer/xfa_codec_fuzzer.h
@@ -49,7 +49,7 @@ class XFACodecFuzzer {
void Release() override {}
bool ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override {
- if (offset < 0 || offset >= m_size)
+ if (offset < 0 || static_cast<size_t>(offset) >= m_size)
return false;
if (offset + size > m_size)
size = m_size - offset;