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