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 27set -eu 28 29# Have a copy of AOM and a build directory ready. 30if [[ $# -ne 2 ]]; then 31 echo "Pass in the AOM source tree as first argument, and a build directory " 32 echo "as the second argument. The AOM source tree can be obtained via: " 33 echo " git clone https://aomedia.googlesource.com/aom" 34 exit 2 35fi 36if [[ -z "${CC:-}" ]]; then 37 echo "Set the CC environment variable to point to your C compiler." 38 exit 2 39fi 40if [[ -z "${CXX:-}" ]]; then 41 echo "Set the CXX environment variable to point to your C++ compiler." 42 exit 2 43fi 44 45AOM_DIR=$1 46BUILD_DIR=$2 47# Run CMake with address sanitizer enabled and build the codec. 48# Enable DO_RANGE_CHECK_CLAMP to suppress the noise of integer overflows 49# in the transform functions. Also set memory limits. 50EXTRA_C_FLAGS='-UNDEBUG -DDO_RANGE_CHECK_CLAMP=1 -DAOM_MAX_ALLOCABLE_MEMORY=1073741824' 51cd "${BUILD_DIR}" 52cmake "${AOM_DIR}" -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCONFIG_PIC=1 \ 53 -DFORCE_HIGHBITDEPTH_DECODING=0 \ 54 -DCONFIG_AV1_ENCODER=0 -DENABLE_EXAMPLES=0 -DENABLE_DOCS=0 -DENABLE_TESTS=0 \ 55 -DCONFIG_SIZE_LIMIT=1 -DDECODE_HEIGHT_LIMIT=12288 -DDECODE_WIDTH_LIMIT=12288 \ 56 -DAOM_EXTRA_C_FLAGS="${EXTRA_C_FLAGS}" \ 57 -DAOM_EXTRA_CXX_FLAGS="${EXTRA_C_FLAGS}" -DSANITIZE=fuzzer-no-link,address 58 59# Build the codec. 60make -j$(nproc) 61 62# Build the av1 fuzzer 63$CXX -std=c++11 -I${AOM_DIR} -I${BUILD_DIR} \ 64 -g -fsanitize=fuzzer,address \ 65 ${AOM_DIR}/examples/av1_dec_fuzzer.cc -o ${BUILD_DIR}/av1_dec_fuzzer \ 66 ${BUILD_DIR}/libaom.a 67 68echo "Fuzzer built at ${BUILD_DIR}/av1_dec_fuzzer." 69echo "Create a corpus directory, copy IVF files in there, and run:" 70echo " av1_dec_fuzzer CORPUS_DIR" 71