Skip to content

Commit

Permalink
Fuzz harness.galk (#271)
Browse files Browse the repository at this point in the history
* move harness to testing area

* now it compiles well on mac

* moving documentation to wiki
  • Loading branch information
galkahana authored Jun 28, 2024
1 parent 6efa34b commit 53909bf
Show file tree
Hide file tree
Showing 686 changed files with 20 additions and 54 deletions.
12 changes: 4 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ option(USE_UNBUNDLED_FALLBACK_BUNDLED "When USE_BUNDLED is false and a certain
option(PDFHUMMUS_NO_DCT "Whether to drop support for DCT streams parsing (will not use LibJpeg)")
option(PDFHUMMUS_NO_TIFF "Whether to drop TIFF Images support (will not use LibTiff)" )
option(PDFHUMMUS_NO_PNG "Whether to drop PNG Images support (will not use LibPng)" )
option(BUILD_FUZZING_HARNESS "Build the fuzzing harness, requires LLVM's clang")

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

Expand Down Expand Up @@ -158,15 +157,12 @@ if(PROJECT_IS_TOP_LEVEL AND EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/PDFWriterTesting)
# avoid installing the testing lib altogether when included in another project.
# it's annoying when in parent all, and more annoying to then get the tests added
# to the parent project ctest.
enable_testing()
ADD_SUBDIRECTORY(PDFWriterTesting)
endif()

if(BUILD_FUZZING_HARNESS)
add_compile_options(-fsanitize=fuzzer,address -g -O2)
# option specific for testing
option(BUILD_FUZZING_HARNESS "Build the fuzzing harness, requires LLVM's clang")

add_executable(PDFParserFuzzingHarness PDFWriterTesting/PDFParserFuzzingHarness.cpp)
target_link_libraries(PDFParserFuzzingHarness PDFWriter -O2 -fsanitize=fuzzer,address -fuse-ld=lld)
enable_testing()
ADD_SUBDIRECTORY(PDFWriterTesting)
endif()

include(InstallRequiredSystemLibraries)
Expand Down
3 changes: 3 additions & 0 deletions LibPng/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ if (${CMAKE_HOST_SYSTEM_PROCESSOR} STREQUAL "aarch64" OR ${CMAKE_HOST_SYSTEM_PRO
)
endif()

# drop obsolete symbol, causing trouble when compiling with clang on mac, and in general unneeded
target_compile_options(LibPng PRIVATE -UTARGET_OS_MAC)

if(WIN32 AND BUILD_SHARED_LIBS)
target_compile_definitions(LibPng PUBLIC PNG_USE_DLL)
endif()
Expand Down
11 changes: 9 additions & 2 deletions PDFWriterTesting/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,20 @@ foreach (test ${TestsToRun})
add_test (NAME ${TName} COMMAND PDFWriterTesting ${TName} ${CMAKE_CURRENT_SOURCE_DIR}/Materials ${CMAKE_BINARY_DIR}/Testing/Output)
endforeach ()

# fuzz test specific
file(GLOB fuzztestfiles ${CMAKE_CURRENT_SOURCE_DIR}/Materials/fuzzing/*)
# fuzz test errors specific
file(GLOB fuzztestfiles ${CMAKE_CURRENT_SOURCE_DIR}/Materials/fuzzing/errors/*)
foreach (fuzztestfile ${fuzztestfiles})
get_filename_component (TName ${fuzztestfile} NAME)
add_test (NAME FuzzTest_${TName} COMMAND PDFWriterTesting PDFParserFuzzSanity ${CMAKE_CURRENT_SOURCE_DIR}/Materials ${CMAKE_BINARY_DIR}/Testing/Output ${fuzztestfile} FuzzTest_${TName}.txt)
endforeach ()

# fuzz testing with fuzzing harness
if(BUILD_FUZZING_HARNESS)
add_executable(PDFParserFuzzingHarness PDFParserFuzzingHarness.cpp)
target_compile_options(PDFParserFuzzingHarness PRIVATE -fsanitize=fuzzer,address -g -O2)
target_link_libraries(PDFParserFuzzingHarness PDFWriter -O2 -fsanitize=fuzzer,address -fuse-ld=lld)
endif()


# create temp dir for output files
set (TmpOutputDir ${CMAKE_BINARY_DIR}/Testing/Output)
Expand Down
Loading

0 comments on commit 53909bf

Please sign in to comment.