Skip to content

Commit 1f6ad44

Browse files
authored
Fix oss-fuzz build (#256)
Improves fuzzing build
1 parent d479df2 commit 1f6ad44

File tree

4 files changed

+17
-16
lines changed

4 files changed

+17
-16
lines changed

CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,5 +238,13 @@ install(FILES "${CMAKE_BINARY_DIR}/${PROJECT_NAME}.pc"
238238
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND OJPH_BUILD_TESTS)
239239
enable_testing()
240240
add_subdirectory(tests)
241+
endif()
242+
243+
################################################################################################
244+
# Testing and fuzzing (OJPH_BUILD_FUZZER)
245+
################################################################################################
246+
247+
if(OJPH_BUILD_FUZZER)
241248
add_subdirectory(fuzzing)
242249
endif()
250+

docs/fuzzing.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
# Fuzzer Target #
22

3-
Fuzzer targets can be build using the `OJPH_BUILD_FUZZER` build option. The Dockerfile in the `fuzzing directory` allows local testing:
3+
Fuzzer targets intended for use with [oss-fuzz](https://oss-fuzz.com/) can be build using the `OJPH_BUILD_FUZZER` build option.
4+
5+
The targets can be run locally as follows:
46

57
```sh
6-
podman build -t openjph-fuzz -f fuzzing/Dockerfile
7-
podman run -it --rm -v $(pwd):/app/ojph/ openjph-fuzz bash
8-
image# mkdir /app/build/
9-
image# cd /app/build/
10-
image# cmake /app/ojph -DCMAKE_CXX_FLAGS="-fsanitize=fuzzer,address" -DOJPH_BUILD_FUZZER=ON -DBUILD_SHARED_LIBS=OFF
11-
image# make
12-
image# ./fuzzing/ojph_expand_fuzz_target /app/jp2k_test_codestreams/openjph/*.j2c
8+
cd build
9+
cmake .. -DOJPH_BUILD_FUZZER=ON
10+
./fuzzing/ojph_expand_fuzz_target <test case>
1311
```

fuzzing/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
# detect whether we are within the oss fuzz environment
12
if(DEFINED ENV{LIB_FUZZING_ENGINE})
3+
# if yes, we can link against the main function of the fuzzing engine
24
link_libraries($ENV{LIB_FUZZING_ENGINE})
35
else()
6+
# if not, we need to define our main function
47
add_compile_definitions(OJPH_FUZZ_TARGET_MAIN)
58
endif()
69

fuzzing/Dockerfile

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)