From 9d4b2c5d6b201c102def41beee61f161638303d5 Mon Sep 17 00:00:00 2001 From: Pierre-Anthony Lemieux Date: Wed, 25 Feb 2026 10:32:01 -0800 Subject: [PATCH] Fix oss-fuzz build --- CMakeLists.txt | 8 ++++++++ docs/fuzzing.md | 14 ++++++-------- fuzzing/CMakeLists.txt | 3 +++ fuzzing/Dockerfile | 8 -------- 4 files changed, 17 insertions(+), 16 deletions(-) delete mode 100644 fuzzing/Dockerfile diff --git a/CMakeLists.txt b/CMakeLists.txt index 67f3575..7d375a6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -238,5 +238,13 @@ install(FILES "${CMAKE_BINARY_DIR}/${PROJECT_NAME}.pc" if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND OJPH_BUILD_TESTS) enable_testing() add_subdirectory(tests) +endif() + +################################################################################################ +# Testing and fuzzing (OJPH_BUILD_FUZZER) +################################################################################################ + +if(OJPH_BUILD_FUZZER) add_subdirectory(fuzzing) endif() + diff --git a/docs/fuzzing.md b/docs/fuzzing.md index 39d8e30..86855ad 100644 --- a/docs/fuzzing.md +++ b/docs/fuzzing.md @@ -1,13 +1,11 @@ # Fuzzer Target # -Fuzzer targets can be build using the `OJPH_BUILD_FUZZER` build option. The Dockerfile in the `fuzzing directory` allows local testing: +Fuzzer targets intended for use with [oss-fuzz](https://oss-fuzz.com/) can be build using the `OJPH_BUILD_FUZZER` build option. + +The targets can be run locally as follows: ```sh -podman build -t openjph-fuzz -f fuzzing/Dockerfile -podman run -it --rm -v $(pwd):/app/ojph/ openjph-fuzz bash -image# mkdir /app/build/ -image# cd /app/build/ -image# cmake /app/ojph -DCMAKE_CXX_FLAGS="-fsanitize=fuzzer,address" -DOJPH_BUILD_FUZZER=ON -DBUILD_SHARED_LIBS=OFF -image# make -image# ./fuzzing/ojph_expand_fuzz_target /app/jp2k_test_codestreams/openjph/*.j2c +cd build +cmake .. -DOJPH_BUILD_FUZZER=ON +./fuzzing/ojph_expand_fuzz_target ``` diff --git a/fuzzing/CMakeLists.txt b/fuzzing/CMakeLists.txt index dc25af0..cb00f98 100644 --- a/fuzzing/CMakeLists.txt +++ b/fuzzing/CMakeLists.txt @@ -1,6 +1,9 @@ +# detect whether we are within the oss fuzz environment if(DEFINED ENV{LIB_FUZZING_ENGINE}) + # if yes, we can link against the main function of the fuzzing engine link_libraries($ENV{LIB_FUZZING_ENGINE}) else() + # if not, we need to define our main function add_compile_definitions(OJPH_FUZZ_TARGET_MAIN) endif() diff --git a/fuzzing/Dockerfile b/fuzzing/Dockerfile deleted file mode 100644 index deb381b..0000000 --- a/fuzzing/Dockerfile +++ /dev/null @@ -1,8 +0,0 @@ -FROM gcr.io/oss-fuzz-base/base-builder - -RUN apt-get update -RUN apt-get -y install cmake -RUN apt-get -y install libtiff-dev - -WORKDIR /app -RUN git clone --depth 1 https://github.com/aous72/jp2k_test_codestreams.git