2016-11-09 03:35:29 +00:00
|
|
|
#!/bin/bash -eux
|
2016-11-08 19:15:23 +00:00
|
|
|
# Copyright 2016 Google Inc.
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
#
|
|
|
|
################################################################################
|
|
|
|
|
|
|
|
# Build dependencies.
|
2016-11-18 19:16:38 +00:00
|
|
|
export FFMPEG_DEPS_PATH=$SRC/ffmpeg_deps
|
2016-11-08 19:15:23 +00:00
|
|
|
mkdir -p $FFMPEG_DEPS_PATH
|
|
|
|
|
2016-11-18 19:16:38 +00:00
|
|
|
cd $SRC
|
2016-11-09 03:54:02 +00:00
|
|
|
bzip2 -f -d alsa-lib-*
|
2016-11-08 19:15:23 +00:00
|
|
|
tar xf alsa-lib-*
|
|
|
|
cd alsa-lib-*
|
|
|
|
./configure --prefix="$FFMPEG_DEPS_PATH" --enable-static --disable-shared
|
|
|
|
make clean
|
|
|
|
make -j$(nproc) all
|
|
|
|
make install
|
|
|
|
|
2016-11-18 19:16:38 +00:00
|
|
|
cd $SRC/drm
|
2016-11-08 19:15:23 +00:00
|
|
|
# Requires xutils-dev libpciaccess-dev
|
|
|
|
./autogen.sh
|
|
|
|
./configure --prefix="$FFMPEG_DEPS_PATH" --enable-static
|
|
|
|
make clean
|
|
|
|
make -j$(nproc)
|
|
|
|
make install
|
|
|
|
|
2016-11-18 19:16:38 +00:00
|
|
|
cd $SRC/fdk-aac
|
2016-11-08 19:15:23 +00:00
|
|
|
autoreconf -fiv
|
|
|
|
./configure --prefix="$FFMPEG_DEPS_PATH" --disable-shared
|
|
|
|
make clean
|
|
|
|
make -j$(nproc) all
|
|
|
|
make install
|
|
|
|
|
2016-11-18 19:16:38 +00:00
|
|
|
cd $SRC
|
2016-11-08 19:15:23 +00:00
|
|
|
tar xzf lame.tar.gz
|
|
|
|
cd lame-*
|
|
|
|
./configure --prefix="$FFMPEG_DEPS_PATH" --enable-static
|
|
|
|
make clean
|
|
|
|
make -j$(nproc)
|
|
|
|
make install
|
|
|
|
|
2016-11-18 19:16:38 +00:00
|
|
|
cd $SRC/libXext
|
2016-11-08 19:15:23 +00:00
|
|
|
./autogen.sh
|
|
|
|
./configure --prefix="$FFMPEG_DEPS_PATH" --enable-static
|
|
|
|
make clean
|
|
|
|
make -j$(nproc)
|
|
|
|
make install
|
|
|
|
|
2016-11-18 19:16:38 +00:00
|
|
|
cd $SRC/libXfixes
|
2016-11-08 19:15:23 +00:00
|
|
|
./autogen.sh
|
|
|
|
./configure --prefix="$FFMPEG_DEPS_PATH" --enable-static
|
|
|
|
make clean
|
|
|
|
make -j$(nproc)
|
|
|
|
make install
|
|
|
|
|
2016-11-18 19:16:38 +00:00
|
|
|
cd $SRC/libva
|
2016-11-08 19:15:23 +00:00
|
|
|
./autogen.sh
|
|
|
|
./configure --prefix="$FFMPEG_DEPS_PATH" --enable-static --disable-shared
|
|
|
|
make clean
|
|
|
|
make -j$(nproc) all
|
|
|
|
make install
|
|
|
|
|
2016-11-18 19:16:38 +00:00
|
|
|
cd $SRC/libvdpau
|
2016-11-08 19:15:23 +00:00
|
|
|
./autogen.sh
|
|
|
|
./configure --prefix="$FFMPEG_DEPS_PATH" --enable-static --disable-shared
|
|
|
|
make clean
|
|
|
|
make -j$(nproc) all
|
|
|
|
make install
|
|
|
|
|
2016-11-18 19:16:38 +00:00
|
|
|
cd $SRC/libvpx
|
2016-11-08 19:15:23 +00:00
|
|
|
LDFLAGS="$CXXFLAGS $LDFLAGS" ./configure --prefix="$FFMPEG_DEPS_PATH" \
|
|
|
|
--disable-examples --disable-unit-tests
|
|
|
|
make clean
|
|
|
|
make -j$(nproc) all
|
|
|
|
make install
|
|
|
|
|
2016-11-18 19:16:38 +00:00
|
|
|
cd $SRC/ogg
|
2016-11-08 19:15:23 +00:00
|
|
|
./autogen.sh
|
|
|
|
./configure --prefix="$FFMPEG_DEPS_PATH" --enable-static
|
|
|
|
make clean
|
|
|
|
make -j$(nproc)
|
|
|
|
make install
|
|
|
|
|
2016-11-18 19:16:38 +00:00
|
|
|
cd $SRC/opus
|
2016-11-08 19:15:23 +00:00
|
|
|
./autogen.sh
|
|
|
|
./configure --prefix="$FFMPEG_DEPS_PATH" --enable-static
|
|
|
|
make clean
|
|
|
|
make -j$(nproc) all
|
|
|
|
make install
|
|
|
|
|
2016-11-18 19:16:38 +00:00
|
|
|
cd $SRC/theora
|
2016-11-08 19:15:23 +00:00
|
|
|
# theora requires ogg, need to pass its location to the "configure" script.
|
|
|
|
CFLAGS="$CFLAGS -fPIC" LDFLAGS="$LDFLAGS -L$FFMPEG_DEPS_PATH/lib/" \
|
|
|
|
CPPFLAGS="$CXXFLAGS -I$FFMPEG_DEPS_PATH/include/" \
|
|
|
|
LD_LIBRARY_PATH="$FFMPEG_DEPS_PATH/lib/" \
|
|
|
|
./autogen.sh --prefix="$FFMPEG_DEPS_PATH" --enable-static --disable-examples
|
|
|
|
make clean
|
|
|
|
make -j$(nproc)
|
|
|
|
make install
|
|
|
|
|
2016-11-18 19:16:38 +00:00
|
|
|
cd $SRC/vorbis
|
2016-11-08 19:15:23 +00:00
|
|
|
./autogen.sh
|
|
|
|
./configure --prefix="$FFMPEG_DEPS_PATH" --enable-static
|
|
|
|
make clean
|
|
|
|
make -j$(nproc)
|
|
|
|
make install
|
|
|
|
|
2016-11-18 19:16:38 +00:00
|
|
|
cd $SRC/x264
|
2016-11-08 19:15:23 +00:00
|
|
|
LDFLAGS="$CXXFLAGS $LDFLAGS" ./configure --prefix="$FFMPEG_DEPS_PATH" \
|
|
|
|
--enable-static
|
|
|
|
make clean
|
|
|
|
make -j$(nproc)
|
|
|
|
make install
|
|
|
|
|
2016-11-18 19:16:38 +00:00
|
|
|
cd $SRC/x265/build/linux
|
2016-11-08 19:15:23 +00:00
|
|
|
cmake -G "Unix Makefiles" \
|
|
|
|
-DCMAKE_C_COMPILER=$CC -DCMAKE_CXX_COMPILER=$CXX \
|
|
|
|
-DCMAKE_C_FLAGS="$CFLAGS" -DCMAKE_CXX_FLAGS="$CXXFLAGS" \
|
|
|
|
-DCMAKE_INSTALL_PREFIX="$FFMPEG_DEPS_PATH" -DENABLE_SHARED:bool=off \
|
|
|
|
../../source
|
|
|
|
make clean
|
|
|
|
make -j$(nproc) x265-static
|
|
|
|
make install
|
|
|
|
|
|
|
|
# Remove shared libraries to avoid accidental linking against them.
|
|
|
|
rm $FFMPEG_DEPS_PATH/lib/*.so
|
|
|
|
rm $FFMPEG_DEPS_PATH/lib/*.so.*
|
|
|
|
|
2016-11-29 19:33:34 +00:00
|
|
|
# Build ffmpeg.
|
2016-11-18 19:16:38 +00:00
|
|
|
cd $SRC/ffmpeg
|
2016-11-08 19:15:23 +00:00
|
|
|
PKG_CONFIG_PATH="$FFMPEG_DEPS_PATH/lib/pkgconfig" ./configure \
|
|
|
|
--cc=$CC --cxx=$CXX --ld="$CXX $CXXFLAGS -std=c++11" \
|
|
|
|
--extra-cflags="-I$FFMPEG_DEPS_PATH/include" \
|
|
|
|
--extra-ldflags="-L$FFMPEG_DEPS_PATH/lib" \
|
|
|
|
--prefix="$FFMPEG_DEPS_PATH" \
|
|
|
|
--pkg-config-flags="--static" \
|
|
|
|
--enable-gpl \
|
|
|
|
--enable-libass \
|
|
|
|
--enable-libfdk-aac \
|
|
|
|
--enable-libfreetype \
|
|
|
|
--enable-libmp3lame \
|
|
|
|
--enable-libopus \
|
|
|
|
--enable-libtheora \
|
|
|
|
--enable-libvorbis \
|
|
|
|
--enable-libvpx \
|
|
|
|
--enable-libx264 \
|
|
|
|
--enable-libx265 \
|
|
|
|
--enable-nonfree \
|
|
|
|
--disable-shared
|
|
|
|
make clean
|
|
|
|
make -j$(nproc) install
|
|
|
|
|
2016-11-10 12:22:50 +00:00
|
|
|
# Download test sampes, will be used as seed corpus.
|
2016-11-18 19:16:38 +00:00
|
|
|
export TEST_SAMPLES_PATH=$SRC/ffmpeg/fate-suite/
|
2016-11-10 12:22:50 +00:00
|
|
|
make fate-rsync SAMPLES=$TEST_SAMPLES_PATH
|
2016-11-08 19:15:23 +00:00
|
|
|
|
|
|
|
# Build the fuzzers.
|
2016-11-18 19:16:38 +00:00
|
|
|
cd $SRC/ffmpeg
|
2016-11-08 19:15:23 +00:00
|
|
|
|
|
|
|
export TEMP_VAR_CODEC="AV_CODEC_ID_H264"
|
|
|
|
export TEMP_VAR_CODEC_TYPE="VIDEO"
|
|
|
|
|
2016-11-21 16:23:32 +00:00
|
|
|
FFMPEG_FUZZERS_COMMON_FLAGS="-lfuzzer /usr/local/lib/libc++.a \
|
2016-11-08 19:15:23 +00:00
|
|
|
-L$FFMPEG_DEPS_PATH/lib \
|
|
|
|
-Llibavcodec -Llibavdevice -Llibavfilter -Llibavformat -Llibavresample \
|
|
|
|
-Llibavutil -Llibpostproc -Llibswscale -Llibswresample \
|
|
|
|
-Wl,--as-needed -Wl,-z,noexecstack -Wl,--warn-common \
|
|
|
|
-Wl,-rpath-link=libpostproc:libswresample:libswscale:libavfilter:libavdevice:libavformat:libavcodec:libavutil:libavresample \
|
|
|
|
-lavdevice -lavfilter -lavformat -lavcodec -lswresample -lswscale \
|
|
|
|
-lavutil -ldl -lxcb -lxcb-shm -lxcb -lxcb-xfixes -lxcb -lxcb-shape -lxcb \
|
2016-11-10 12:22:50 +00:00
|
|
|
-lX11 -lasound -lm -lbz2 -lz -pthread -lva-x11 -lXext -lXfixes \
|
|
|
|
-lx264 -lx265 -lvpx -lva -lvorbis -logg -lvorbisenc -lopus -lmp3lame \
|
|
|
|
-lfdk-aac -ltheora -ltheoraenc -ltheoradec -lvdpau -lva-drm -ldrm"
|
2016-11-08 19:15:23 +00:00
|
|
|
|
|
|
|
# Build fuzzers for audio formats.
|
|
|
|
CODEC_TYPE="AUDIO"
|
|
|
|
CODEC_NAMES="AV_CODEC_ID_AAC \
|
|
|
|
AV_CODEC_ID_AC3 \
|
|
|
|
AV_CODEC_ID_ADPCM_ADX \
|
|
|
|
AV_CODEC_ID_AMR_NB \
|
|
|
|
AV_CODEC_ID_AMR_WB \
|
|
|
|
AV_CODEC_ID_DTS \
|
|
|
|
AV_CODEC_ID_EAC3 \
|
|
|
|
AV_CODEC_ID_FLAC \
|
|
|
|
AV_CODEC_ID_GSM_MS \
|
|
|
|
AV_CODEC_ID_MP2 \
|
|
|
|
AV_CODEC_ID_MP3 \
|
|
|
|
AV_CODEC_ID_QCELP \
|
|
|
|
AV_CODEC_ID_SIPR \
|
|
|
|
AV_CODEC_ID_WAVPACK"
|
|
|
|
|
|
|
|
for codec in $CODEC_NAMES; do
|
2016-11-10 12:22:50 +00:00
|
|
|
fuzzer_name=ffmpeg_${CODEC_TYPE}_${codec}_fuzzer
|
|
|
|
|
2016-11-08 19:15:23 +00:00
|
|
|
$CC $CFLAGS -I${FFMPEG_DEPS_PATH}/include \
|
2016-11-18 19:16:38 +00:00
|
|
|
$SRC/ffmpeg/doc/examples/decoder_targeted.c \
|
|
|
|
-o $OUT/${fuzzer_name} \
|
2016-11-08 19:15:23 +00:00
|
|
|
-DFFMPEG_CODEC=${codec} -DFUZZ_FFMPEG_${CODEC_TYPE}= \
|
|
|
|
${FFMPEG_FUZZERS_COMMON_FLAGS}
|
2016-11-10 14:07:29 +00:00
|
|
|
|
2016-11-18 19:16:38 +00:00
|
|
|
echo -en "[libfuzzer]\nmax_len = 1000000\n" > $OUT/${fuzzer_name}.options
|
2016-11-08 19:15:23 +00:00
|
|
|
done
|
|
|
|
|
|
|
|
# Build fuzzers for subtitles formats.
|
|
|
|
CODEC_TYPE="SUBTITLE"
|
|
|
|
CODEC_NAMES="AV_CODEC_ID_DVD_SUBTITLE \
|
|
|
|
AV_CODEC_ID_MOV_TEXT \
|
|
|
|
AV_CODEC_ID_SUBRIP"
|
|
|
|
|
|
|
|
for codec in $CODEC_NAMES; do
|
2016-11-10 12:22:50 +00:00
|
|
|
fuzzer_name=ffmpeg_${CODEC_TYPE}_${codec}_fuzzer
|
|
|
|
|
2016-11-08 19:15:23 +00:00
|
|
|
$CC $CFLAGS -I${FFMPEG_DEPS_PATH}/include \
|
2016-11-18 19:16:38 +00:00
|
|
|
$SRC/ffmpeg/doc/examples/decoder_targeted.c \
|
|
|
|
-o $OUT/${fuzzer_name} \
|
2016-11-08 19:15:23 +00:00
|
|
|
-DFFMPEG_CODEC=${codec} -DFUZZ_FFMPEG_${CODEC_TYPE}= \
|
|
|
|
${FFMPEG_FUZZERS_COMMON_FLAGS}
|
|
|
|
done
|
|
|
|
|
|
|
|
# Build fuzzers for video formats.
|
|
|
|
CODEC_TYPE="VIDEO"
|
|
|
|
CODEC_NAMES="AV_CODEC_ID_AMV \
|
|
|
|
AV_CODEC_ID_BINTEXT \
|
|
|
|
AV_CODEC_ID_BMP \
|
|
|
|
AV_CODEC_ID_CINEPAK \
|
|
|
|
AV_CODEC_ID_DVVIDEO \
|
|
|
|
AV_CODEC_ID_ESCAPE130 \
|
|
|
|
AV_CODEC_ID_FLIC \
|
|
|
|
AV_CODEC_ID_FLV1 \
|
|
|
|
AV_CODEC_ID_FRAPS \
|
|
|
|
AV_CODEC_ID_GIF \
|
|
|
|
AV_CODEC_ID_H263 \
|
|
|
|
AV_CODEC_ID_H263I \
|
|
|
|
AV_CODEC_ID_H264 \
|
|
|
|
AV_CODEC_ID_INDEO2 \
|
|
|
|
AV_CODEC_ID_INTERPLAY_VIDEO \
|
|
|
|
AV_CODEC_ID_JPEGLS \
|
|
|
|
AV_CODEC_ID_KMVC \
|
|
|
|
AV_CODEC_ID_MDEC \
|
|
|
|
AV_CODEC_ID_MJPEG \
|
|
|
|
AV_CODEC_ID_MPEG1VIDEO \
|
|
|
|
AV_CODEC_ID_MPEG2VIDEO \
|
|
|
|
AV_CODEC_ID_MPEG4 \
|
|
|
|
AV_CODEC_ID_MSVIDEO1 \
|
|
|
|
AV_CODEC_ID_PCX \
|
|
|
|
AV_CODEC_ID_PGM \
|
|
|
|
AV_CODEC_ID_PICTOR \
|
|
|
|
AV_CODEC_ID_PNG \
|
|
|
|
AV_CODEC_ID_RPZA \
|
|
|
|
AV_CODEC_ID_RV40 \
|
|
|
|
AV_CODEC_ID_SANM \
|
|
|
|
AV_CODEC_ID_SMC \
|
|
|
|
AV_CODEC_ID_SUNRAST \
|
|
|
|
AV_CODEC_ID_SVQ1 \
|
|
|
|
AV_CODEC_ID_SVQ3 \
|
|
|
|
AV_CODEC_ID_TARGA \
|
|
|
|
AV_CODEC_ID_TIFF \
|
|
|
|
AV_CODEC_ID_VP3 \
|
|
|
|
AV_CODEC_ID_VP5 \
|
|
|
|
AV_CODEC_ID_VP6 \
|
|
|
|
AV_CODEC_ID_VP6F \
|
|
|
|
AV_CODEC_ID_VP8 \
|
|
|
|
AV_CODEC_ID_ZMBV"
|
|
|
|
|
|
|
|
for codec in $CODEC_NAMES; do
|
2016-11-10 12:22:50 +00:00
|
|
|
fuzzer_name=ffmpeg_${CODEC_TYPE}_${codec}_fuzzer
|
|
|
|
|
2016-11-08 19:15:23 +00:00
|
|
|
$CC $CFLAGS -I${FFMPEG_DEPS_PATH}/include \
|
2016-11-18 19:16:38 +00:00
|
|
|
$SRC/ffmpeg/doc/examples/decoder_targeted.c \
|
|
|
|
-o $OUT/${fuzzer_name} \
|
2016-11-08 19:15:23 +00:00
|
|
|
-DFFMPEG_CODEC=${codec} -DFUZZ_FFMPEG_${CODEC_TYPE}= \
|
|
|
|
${FFMPEG_FUZZERS_COMMON_FLAGS}
|
2016-11-10 14:07:29 +00:00
|
|
|
|
2016-11-18 19:16:38 +00:00
|
|
|
echo -en "[libfuzzer]\nmax_len = 1000000\n" > $OUT/${fuzzer_name}.options
|
2016-11-08 19:15:23 +00:00
|
|
|
done
|
2016-11-10 12:22:50 +00:00
|
|
|
|
|
|
|
# Find relevant corpus in test samples and archive them for every fuzzer.
|
2016-11-18 19:16:38 +00:00
|
|
|
cd $SRC
|
|
|
|
python group_seed_corpus.py $TEST_SAMPLES_PATH $OUT/
|