• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash -eu
2# Copyright 2019 Google Inc.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#      http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
16################################################################################
17
18export PKG_CONFIG_PATH=/work/lib/pkgconfig
19export LDFLAGS="$CXXFLAGS"
20
21# libz
22pushd $SRC/zlib
23./configure --static --prefix=$WORK
24make -j$(nproc) all
25make install
26popd
27
28# libexif
29pushd $SRC/libexif
30autoreconf -fi
31./configure \
32  --enable-shared=no \
33  --disable-docs \
34  --disable-dependency-tracking \
35  --prefix=$WORK
36make -j$(nproc)
37make install
38popd
39
40# aom
41pushd $SRC/aom
42mkdir -p build/linux
43cd build/linux
44cmake -G "Unix Makefiles" \
45  -DCMAKE_C_COMPILER=$CC -DCMAKE_CXX_COMPILER=$CXX \
46  -DCMAKE_C_FLAGS="$CFLAGS" -DCMAKE_CXX_FLAGS="$CXXFLAGS" \
47  -DCMAKE_INSTALL_PREFIX=$WORK -DCMAKE_INSTALL_LIBDIR=lib \
48  -DENABLE_SHARED:bool=off -DCONFIG_PIC=1 \
49  -DENABLE_EXAMPLES=0 -DENABLE_DOCS=0 -DENABLE_TESTS=0 \
50  -DCONFIG_SIZE_LIMIT=1 \
51  -DDECODE_HEIGHT_LIMIT=12288 -DDECODE_WIDTH_LIMIT=12288 \
52  -DDO_RANGE_CHECK_CLAMP=1 \
53  -DAOM_MAX_ALLOCABLE_MEMORY=536870912 \
54  -DAOM_TARGET_CPU=generic \
55  ../../
56make clean
57make -j$(nproc)
58make install
59popd
60
61# libheif
62pushd $SRC/libheif
63autoreconf -fi
64./configure \
65  --disable-shared \
66  --enable-static \
67  --disable-examples \
68  --disable-go \
69  --prefix=$WORK
70make clean
71make -j$(nproc)
72make install
73popd
74
75# libjpeg-turbo
76pushd $SRC/libjpeg-turbo
77cmake . -DCMAKE_INSTALL_PREFIX=$WORK -DENABLE_STATIC:bool=on
78make -j$(nproc)
79make install
80popd
81
82# libpng
83pushd $SRC/libpng
84sed -ie "s/option WARNING /option WARNING disabled/" scripts/pnglibconf.dfa
85autoreconf -fi
86./configure \
87  --prefix=$WORK \
88  --disable-shared \
89  --disable-dependency-tracking
90make -j$(nproc)
91make install
92popd
93
94# libgif
95pushd $SRC/libgif
96make libgif.a libgif.so install-include install-lib OFLAGS="-O2" PREFIX=$WORK
97popd
98
99# libwebp
100pushd $SRC/libwebp
101autoreconf -fi
102./configure \
103  --enable-libwebpdemux \
104  --enable-libwebpmux \
105  --disable-shared \
106  --disable-jpeg \
107  --disable-tiff \
108  --disable-gif \
109  --disable-wic \
110  --disable-threading \
111  --disable-dependency-tracking \
112  --prefix=$WORK
113make -j$(nproc)
114make install
115popd
116
117# libtiff ... a bug in libtiff master as of 20 Nov 2019 means we have to
118# explicitly disable lzma
119pushd $SRC/libtiff
120autoreconf -fi
121./configure \
122  --disable-lzma \
123  --disable-shared \
124  --disable-dependency-tracking \
125  --prefix=$WORK
126make -j$(nproc)
127make install
128popd
129
130# libvips
131./autogen.sh \
132  --disable-shared \
133  --disable-gtk-doc \
134  --disable-gtk-doc-html \
135  --disable-dependency-tracking \
136  --prefix=$WORK
137make -j$(nproc) CCLD=$CXX
138make install
139
140# Merge the seed corpus in a single directory, exclude files larger than 2k
141mkdir -p fuzz/corpus
142find \
143  $SRC/afl-testcases/{gif*,jpeg*,png,tiff,webp}/full/images \
144  fuzz/*_fuzzer_corpus \
145  test/test-suite/images \
146  -type f -size -2k \
147  -exec bash -c 'hash=($(sha1sum {})); mv {} fuzz/corpus/$hash' ';'
148zip -jrq $OUT/seed_corpus.zip fuzz/corpus
149
150# Build fuzzers and link corpus
151for fuzzer in fuzz/*_fuzzer.cc; do
152  target=$(basename "$fuzzer" .cc)
153  $CXX $CXXFLAGS -std=c++11 "$fuzzer" -o "$OUT/$target" \
154    -I$WORK/include \
155    -I/usr/include/glib-2.0 \
156    -I/usr/lib/x86_64-linux-gnu/glib-2.0/include \
157    $WORK/lib/libvips.a \
158    $WORK/lib/libexif.a \
159    $WORK/lib/libturbojpeg.a \
160    $WORK/lib/libpng.a \
161    $WORK/lib/libz.a \
162    $WORK/lib/libgif.a \
163    $WORK/lib/libwebpmux.a \
164    $WORK/lib/libwebpdemux.a \
165    $WORK/lib/libwebp.a \
166    $WORK/lib/libtiff.a \
167    $WORK/lib/libheif.a \
168    $WORK/lib/libaom.a \
169    $LIB_FUZZING_ENGINE \
170    -Wl,-Bstatic \
171    -lfftw3 -lgmodule-2.0 -lgio-2.0 -lgobject-2.0 -lffi -lglib-2.0 -lpcre -lexpat \
172    -lresolv -lsepol -lselinux \
173    -Wl,-Bdynamic -pthread
174  ln -sf "seed_corpus.zip" "$OUT/${target}_seed_corpus.zip"
175done
176
177# Copy options and dictionary files to $OUT
178find fuzz -name '*_fuzzer.dict' -exec cp -v '{}' $OUT ';'
179find fuzz -name '*_fuzzer.options' -exec cp -v '{}' $OUT ';'
180