From 20e92f7d40740bb2d55fd6f8177b6b6ceb3bc88a Mon Sep 17 00:00:00 2001 From: Vincent Rabaud Date: Thu, 6 Jun 2024 11:57:39 +0200 Subject: [PATCH] Limit the possible fuzz engines. Change-Id: I8f2fd84bc7175e4e74c4fb418fcc4f5549018ac3 --- tests/fuzzer/oss-fuzz/build.sh | 56 ++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/tests/fuzzer/oss-fuzz/build.sh b/tests/fuzzer/oss-fuzz/build.sh index e8c34eca..6f233ab2 100644 --- a/tests/fuzzer/oss-fuzz/build.sh +++ b/tests/fuzzer/oss-fuzz/build.sh @@ -34,10 +34,15 @@ # And then run the fuzzer locally, for example: # python3 infra/helper.py run_fuzzer libwebp \ # --sanitizer address \ -# animencoder_fuzzer__AnimEncoder.AnimEncoderTest +# animencoder_fuzzer@AnimEncoder.AnimEncoderTest set -eu +# Avoid fuzz engines that do not compile. +if [[ "$FUZZING_ENGINE" != "libfuzzer" ]]; then + exit +fi + # limit allocation size to reduce spurious OOMs WEBP_CFLAGS="$CFLAGS -DWEBP_MAX_IMAGE_SIZE=838860800" # 800MiB @@ -48,36 +53,33 @@ cd build && make -j$(nproc) && cd .. find $SRC/libwebp-test-data -type f -size -32k -iname "*.webp" \ -exec zip -qju fuzz_seed_corpus.zip "{}" \; -# Restrict fuzztest tests to the only compatible fuzz engine: libfuzzer. -if [[ "$FUZZING_ENGINE" == "libfuzzer" ]]; then - # build fuzztests - # The following is taken from https://github.com/google/oss-fuzz/blob/31ac7244748ea7390015455fb034b1f4eda039d9/infra/base-images/base-builder/compile_fuzztests.sh#L59 - # Iterate the fuzz binaries and list each fuzz entrypoint in the binary. For - # each entrypoint create a wrapper script that calls into the binaries the - # given entrypoint as argument. - # The scripts will be named: - # {binary_name}@{fuzztest_entrypoint} - FUZZ_TEST_BINARIES_OUT_PATHS=$(find ./build/tests/fuzzer/ -executable -type f) - echo "Fuzz binaries: $FUZZ_TEST_BINARIES_OUT_PATHS" - for fuzz_main_file in $FUZZ_TEST_BINARIES_OUT_PATHS; do - FUZZ_TESTS=$($fuzz_main_file --list_fuzz_tests | cut -d ' ' -f 4) - cp -f ${fuzz_main_file} $OUT/ - fuzz_basename=$(basename $fuzz_main_file) - chmod -x $OUT/$fuzz_basename - for fuzz_entrypoint in $FUZZ_TESTS; do - TARGET_FUZZER="${fuzz_basename}@$fuzz_entrypoint" - # Write executer script - echo "#!/bin/sh +# build fuzztests +# The following is taken from https://github.com/google/oss-fuzz/blob/31ac7244748ea7390015455fb034b1f4eda039d9/infra/base-images/base-builder/compile_fuzztests.sh#L59 +# Iterate the fuzz binaries and list each fuzz entrypoint in the binary. For +# each entrypoint create a wrapper script that calls into the binaries the +# given entrypoint as argument. +# The scripts will be named: +# {binary_name}@{fuzztest_entrypoint} +FUZZ_TEST_BINARIES_OUT_PATHS=$(find ./build/tests/fuzzer/ -executable -type f) +echo "Fuzz binaries: $FUZZ_TEST_BINARIES_OUT_PATHS" +for fuzz_main_file in $FUZZ_TEST_BINARIES_OUT_PATHS; do + FUZZ_TESTS=$($fuzz_main_file --list_fuzz_tests | cut -d ' ' -f 4) + cp -f ${fuzz_main_file} $OUT/ + fuzz_basename=$(basename $fuzz_main_file) + chmod -x $OUT/$fuzz_basename + for fuzz_entrypoint in $FUZZ_TESTS; do + TARGET_FUZZER="${fuzz_basename}@$fuzz_entrypoint" + # Write executer script + echo "#!/bin/sh # LLVMFuzzerTestOneInput for fuzzer detection. this_dir=\$(dirname \"\$0\") export TEST_DATA_DIRS=\$this_dir/corpus chmod +x \$this_dir/$fuzz_basename \$this_dir/$fuzz_basename --fuzz=$fuzz_entrypoint -- \$@ chmod -x \$this_dir/$fuzz_basename" > $OUT/$TARGET_FUZZER - chmod +x $OUT/$TARGET_FUZZER - done - # Copy data. - cp fuzz_seed_corpus.zip $OUT/${fuzz_basename}_seed_corpus.zip - cp tests/fuzzer/fuzz.dict $OUT/${fuzz_basename}.dict + chmod +x $OUT/$TARGET_FUZZER done -fi +# Copy data. +cp fuzz_seed_corpus.zip $OUT/${fuzz_basename}_seed_corpus.zip +cp tests/fuzzer/fuzz.dict $OUT/${fuzz_basename}.dict +done