• 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
19
20# libz
21pushd $SRC/zlib
22./configure --static --prefix=$WORK
23make -j$(nproc) all
24make install
25popd
26
27# libexif
28pushd $SRC/libexif
29autoreconf -fi
30./configure \
31  --enable-shared=no \
32  --disable-docs \
33  --disable-dependency-tracking \
34  --prefix=$WORK
35make -j$(nproc)
36make install
37popd
38
39# libjpeg-turbo
40pushd $SRC/libjpeg-turbo
41cmake . -DCMAKE_INSTALL_PREFIX=$WORK -DENABLE_STATIC:bool=on
42make -j$(nproc)
43make install
44popd
45
46# libpng
47pushd $SRC/libpng
48sed -ie "s/option WARNING /option WARNING disabled/" scripts/pnglibconf.dfa
49autoreconf -fi
50./configure \
51  --prefix=$WORK \
52  --disable-shared \
53  --disable-dependency-tracking
54make -j$(nproc)
55make install
56popd
57
58# libgif
59pushd $SRC/libgif
60make libgif.a libgif.so install-include install-lib OFLAGS="-O2" PREFIX=$WORK
61popd
62
63# libwebp
64pushd $SRC/libwebp
65autoreconf -fi
66./configure \
67  --enable-libwebpdemux \
68  --enable-libwebpmux \
69  --disable-shared \
70  --disable-jpeg \
71  --disable-tiff \
72  --disable-gif \
73  --disable-wic \
74  --disable-threading \
75  --disable-dependency-tracking \
76  --prefix=$WORK
77make -j$(nproc)
78make install
79popd
80
81# libtiff ... a bug in libtiff master as of 20 Nov 2019 means we have to
82# explicitly disable lzma
83pushd $SRC/libtiff
84autoreconf -fi
85./configure \
86  --disable-lzma \
87  --disable-shared \
88  --disable-dependency-tracking \
89  --prefix=$WORK
90make -j$(nproc)
91make install
92popd
93
94# libvips
95./autogen.sh \
96  --disable-shared \
97  --disable-gtk-doc \
98  --disable-gtk-doc-html \
99  --disable-dependency-tracking \
100  --prefix=$WORK
101make -j$(nproc) CCLD=$CXX
102make install
103
104# Merge the seed corpus in a single directory, exclude files larger than 2k
105mkdir -p fuzz/corpus
106find \
107  $SRC/afl-testcases/{gif*,jpeg*,png,tiff,webp}/full/images \
108  fuzz/*_fuzzer_corpus \
109  test/test-suite/images \
110  -type f -size -2k \
111  -exec bash -c 'hash=($(sha1sum {})); mv {} fuzz/corpus/$hash' ';'
112zip -jrq $OUT/seed_corpus.zip fuzz/corpus
113
114# Build fuzzers and link corpus
115for fuzzer in fuzz/*_fuzzer.cc; do
116  target=$(basename "$fuzzer" .cc)
117  $CXX $CXXFLAGS -std=c++11 "$fuzzer" -o "$OUT/$target" \
118    -I$WORK/include \
119    -I/usr/include/glib-2.0 \
120    -I/usr/lib/x86_64-linux-gnu/glib-2.0/include \
121    $WORK/lib/libvips.a \
122    $WORK/lib/libexif.a \
123    $WORK/lib/libturbojpeg.a \
124    $WORK/lib/libpng.a \
125    $WORK/lib/libz.a \
126    $WORK/lib/libgif.a \
127    $WORK/lib/libwebpmux.a \
128    $WORK/lib/libwebpdemux.a \
129    $WORK/lib/libwebp.a \
130    $WORK/lib/libtiff.a \
131    $LIB_FUZZING_ENGINE \
132    -Wl,-Bstatic \
133    -lfftw3 -lgmodule-2.0 -lgobject-2.0 -lffi -lglib-2.0 -lpcre -lexpat \
134    -Wl,-Bdynamic -pthread
135  ln -sf "seed_corpus.zip" "$OUT/${target}_seed_corpus.zip"
136done
137
138# Copy options and dictionary files to $OUT
139find fuzz -name '*_fuzzer.dict' -exec cp -v '{}' $OUT ';'
140find fuzz -name '*_fuzzer.options' -exec cp -v '{}' $OUT ';'
141