build_av1_dec_fuzzer.sh 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #!/bin/bash
  2. #
  3. # Copyright (c) 2019, Alliance for Open Media. All rights reserved
  4. #
  5. # This source code is subject to the terms of the BSD 2 Clause License and
  6. # the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
  7. # was not distributed with this source code in the LICENSE file, you can
  8. # obtain it at www.aomedia.org/license/software. If the Alliance for Open
  9. # Media Patent License 1.0 was not distributed with this source code in the
  10. # PATENTS file, you can obtain it at www.aomedia.org/license/patent.
  11. #
  12. ###############################################################################
  13. # Fuzzer for libaom decoder.
  14. # ==========================
  15. # Requirements
  16. # ---------------------
  17. # Clang6.0 or above (must support -fsanitize=fuzzer -fsanitize=fuzzer-no-link)
  18. #
  19. # References:
  20. # ---------------------
  21. # http://llvm.org/docs/LibFuzzer.html
  22. # https://github.com/google/oss-fuzz
  23. #
  24. # Steps to build / run
  25. # ---------------------
  26. set -eu
  27. # Have a copy of AOM and a build directory ready.
  28. if [[ $# -ne 2 ]]; then
  29. echo "Pass in the AOM source tree as first argument, and a build directory "
  30. echo "as the second argument. The AOM source tree can be obtained via: "
  31. echo " git clone https://aomedia.googlesource.com/aom"
  32. exit 2
  33. fi
  34. if [[ -z "${CC:-}" ]]; then
  35. echo "Set the CC environment variable to point to your C compiler."
  36. exit 2
  37. fi
  38. if [[ -z "${CXX:-}" ]]; then
  39. echo "Set the CXX environment variable to point to your C++ compiler."
  40. exit 2
  41. fi
  42. AOM_DIR=$1
  43. BUILD_DIR=$2
  44. # Run CMake with address sanitizer enabled and build the codec.
  45. # Enable DO_RANGE_CHECK_CLAMP to suppress the noise of integer overflows
  46. # in the transform functions. Also set memory limits.
  47. EXTRA_C_FLAGS='-UNDEBUG -DDO_RANGE_CHECK_CLAMP=1 -DAOM_MAX_ALLOCABLE_MEMORY=1073741824'
  48. cd "${BUILD_DIR}"
  49. cmake "${AOM_DIR}" -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCONFIG_PIC=1 \
  50. -DFORCE_HIGHBITDEPTH_DECODING=0 \
  51. -DCONFIG_AV1_ENCODER=0 -DENABLE_EXAMPLES=0 -DENABLE_DOCS=0 -DENABLE_TESTS=0 \
  52. -DCONFIG_SIZE_LIMIT=1 -DDECODE_HEIGHT_LIMIT=12288 -DDECODE_WIDTH_LIMIT=12288 \
  53. -DAOM_EXTRA_C_FLAGS="${EXTRA_C_FLAGS}" \
  54. -DAOM_EXTRA_CXX_FLAGS="${EXTRA_C_FLAGS}" -DSANITIZE=fuzzer-no-link,address
  55. # Build the codec.
  56. make -j$(nproc)
  57. # Build the av1 fuzzer
  58. $CXX -std=c++11 -I${AOM_DIR} -I${BUILD_DIR} \
  59. -g -fsanitize=fuzzer,address \
  60. ${AOM_DIR}/examples/av1_dec_fuzzer.cc -o ${BUILD_DIR}/av1_dec_fuzzer \
  61. ${BUILD_DIR}/libaom.a
  62. echo "Fuzzer built at ${BUILD_DIR}/av1_dec_fuzzer."
  63. echo "Create a corpus directory, copy IVF files in there, and run:"
  64. echo " av1_dec_fuzzer CORPUS_DIR"