1#!/bin/bash -eu
2# Copyright 2018 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
18# limit allocation size to reduce spurious OOMs
19WEBP_CFLAGS="$CFLAGS -DWEBP_MAX_IMAGE_SIZE=838860800" # 800MiB
20
21./autogen.sh
22CFLAGS="$WEBP_CFLAGS" ./configure \
23  --enable-asserts \
24  --enable-libwebpdemux \
25  --enable-libwebpmux \
26  --disable-shared \
27  --disable-jpeg \
28  --disable-tiff \
29  --disable-gif \
30  --disable-wic
31make clean
32make -j$(nproc)
33
34find $SRC/libwebp-test-data -type f -size -32k -iname "*.webp" \
35  -exec zip -qju fuzz_seed_corpus.zip "{}" \;
36
37webp_libs=(
38  src/demux/.libs/libwebpdemux.a
39  src/mux/.libs/libwebpmux.a
40  src/.libs/libwebp.a
41  imageio/.libs/libimageio_util.a
42)
43webp_c_fuzzers=(
44  advanced_api_fuzzer
45  animation_api_fuzzer
46  mux_demux_api_fuzzer
47  simple_api_fuzzer
48)
49webp_cxx_fuzzers=(
50  animdecoder_fuzzer
51  animencoder_fuzzer
52  enc_dec_fuzzer
53)
54
55for fuzzer in "${webp_c_fuzzers[@]}"; do
56  $CC $CFLAGS -Isrc -I. tests/fuzzer/${fuzzer}.c -c -o tests/fuzzer/${fuzzer}.o
57  $CXX $CXXFLAGS $LIB_FUZZING_ENGINE \
58    tests/fuzzer/${fuzzer}.o -o $OUT/${fuzzer} \
59    "${webp_libs[@]}"
60done
61
62for fuzzer in "${webp_cxx_fuzzers[@]}"; do
63  $CXX $CXXFLAGS -Isrc -I. $LIB_FUZZING_ENGINE \
64    tests/fuzzer/${fuzzer}.cc -o $OUT/${fuzzer} \
65    "${webp_libs[@]}"
66done
67
68for fuzzer in "${webp_c_fuzzers[@]}" "${webp_cxx_fuzzers[@]}"; do
69  cp fuzz_seed_corpus.zip $OUT/${fuzzer}_seed_corpus.zip
70  cp tests/fuzzer/fuzz.dict $OUT/${fuzzer}.dict
71done
72