CMakeLists.txt | 9 ++++++-- INSTALL | 4 +++ cpp/tests/CMakeLists.txt | 10 ++++----- cpp/tests/pdf_fuzzer.cc | 49 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 65 insertions(+), 7 deletions(-)
New commits: commit f235a53673abdd6cf6c2f69ba63a64fccb258b36 Author: Adam Reichold <[email protected]> Date: Sat Sep 1 11:53:03 2018 +0200 Add fuzzer target from oss-fuzz project and integrate it into the build system via FUZZER CMake variable. diff --git a/CMakeLists.txt b/CMakeLists.txt index 3ad655bf..9c4753e3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,9 +24,15 @@ CHECK_FILE_OFFSET_BITS() include(GNUInstallDirs) +set(ENABLE_FUZZER FALSE) + find_package (ECM 1.6.0 QUIET NO_MODULE) if (ECM_FOUND) include("${ECM_MODULE_DIR}/ECMEnableSanitizers.cmake") + + if(ECM_ENABLE_SANITIZERS MATCHES fuzzer) + set(ENABLE_FUZZER TRUE) + endif() endif() set(POPPLER_MAJOR_VERSION "0") @@ -303,12 +309,10 @@ else() set(CMAKE_CXX_FLAGS "${DEFAULT_COMPILE_WARNINGS} ${CMAKE_CXX_FLAGS}") endif() - include(ConfigureChecks.cmake) configure_file(config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h) configure_file(poppler/poppler-config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/poppler/poppler-config.h) - set(poppler_SRCS goo/gfile.cc goo/GooTimer.cc @@ -717,6 +721,7 @@ show_end_message_yesno("use curl" ENABLE_LIBCURL) show_end_message_yesno("use libopenjpeg2" WITH_OPENJPEG) show_end_message_yesno("use lcms2" USE_CMS) show_end_message_yesno("command line utils" ENABLE_UTILS) +show_end_message_yesno("fuzz target" ENABLE_FUZZER) show_end_message("test data dir" ${TESTDATADIR}) if(NOT ENABLE_SPLASH AND NOT CAIRO_FOUND) diff --git a/INSTALL b/INSTALL index a38a8c00..99ac15f7 100644 --- a/INSTALL +++ b/INSTALL @@ -102,3 +102,7 @@ package) then use -DECM_ENABLE_SANITIZERS to specify the santizers. eg Some options may only be available with clang. Use -DCMAKE_CXX_COMPILER=clang++ to build with clang. + +The sanitizer can also be combined with fuzz testing by using Clang 6.0 +or later and additionally enabling the sanitizer fuzzer which +will enable the fuzz target cpp/tests/pdf_fuzzer. diff --git a/cpp/tests/CMakeLists.txt b/cpp/tests/CMakeLists.txt index 72c1251a..f5be4213 100644 --- a/cpp/tests/CMakeLists.txt +++ b/cpp/tests/CMakeLists.txt @@ -11,15 +11,15 @@ macro(CPP_ADD_SIMPLETEST exe) ${ARGN} ) poppler_add_test(${exe} BUILD_CPP_TESTS ${${test_name}_SOURCES}) - target_link_libraries(${exe} poppler-cpp) + target_link_libraries(${exe} poppler-cpp poppler) if(MSVC) target_link_libraries(${exe} poppler ${poppler_LIBS}) endif() endmacro(CPP_ADD_SIMPLETEST) - cpp_add_simpletest(poppler-dump poppler-dump.cpp ${CMAKE_SOURCE_DIR}/utils/parseargs.cc) -target_link_libraries(poppler-dump poppler) - cpp_add_simpletest(poppler-render poppler-render.cpp ${CMAKE_SOURCE_DIR}/utils/parseargs.cc) -target_link_libraries(poppler-render poppler) + +if(ENABLE_FUZZER) + cpp_add_simpletest(pdf_fuzzer pdf_fuzzer.cc) +endif() diff --git a/cpp/tests/pdf_fuzzer.cc b/cpp/tests/pdf_fuzzer.cc new file mode 100644 index 00000000..f773557e --- /dev/null +++ b/cpp/tests/pdf_fuzzer.cc @@ -0,0 +1,49 @@ +/* +# Copyright 2018 Google Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +################################################################################ +*/ + +#include <cstdint> + +#include <poppler-global.h> +#include <poppler-document.h> +#include <poppler-page.h> +#include <poppler-page-renderer.h> + +static void dummy_error_function(const std::string&, void*) {} + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { + poppler::set_debug_error_function(dummy_error_function, nullptr); + + poppler::document *doc = poppler::document::load_from_raw_data((const char *)data, size); + if (!doc || doc->is_locked()) { + delete doc; + return 0; + } + + poppler::page_renderer r; + for (int i = 0; i < doc->pages(); i++) { + poppler::page *p = doc->create_page(i); + if (!p) { + continue; + } + r.render_page(p); + delete p; + } + + delete doc; + return 0; +} _______________________________________________ poppler mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/poppler
