Commit f235a536 authored by Adam Reichold's avatar Adam Reichold Committed by Albert Astals Cid

Add fuzzer target from oss-fuzz project and integrate it into the build system...

Add fuzzer target from oss-fuzz project and integrate it into the build system via FUZZER CMake variable.
parent c5cdf0cc
Pipeline #6747 passed with stage
in 20 minutes and 50 seconds
......@@ -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)
......
......@@ -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.
......@@ -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()
/*
# 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;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment