• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash -eu
2# Copyright 2021 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
18build_args=(
19  -G Ninja
20  -DBUILD_TESTING=OFF
21  -DJPEGXL_ENABLE_BENCHMARK=OFF
22  -DJPEGXL_ENABLE_DEVTOOLS=ON
23  -DJPEGXL_ENABLE_EXAMPLES=OFF
24  -DJPEGXL_ENABLE_FUZZERS=ON
25  -DJPEGXL_ENABLE_MANPAGES=OFF
26  -DJPEGXL_ENABLE_SJPEG=OFF
27  -DJPEGXL_ENABLE_VIEWERS=OFF
28  -DCMAKE_BUILD_TYPE=Release
29)
30
31# Build and generate a fuzzer corpus in release mode without instrumentation.
32# This is done in a subshell since we change the environment.
33(
34  unset CFLAGS
35  unset CXXFLAGS
36  export AFL_NOOPT=1
37
38  mkdir -p ${WORK}/libjxl-corpus
39  cd ${WORK}/libjxl-corpus
40  cmake "${build_args[@]}" "${SRC}/libjxl"
41  ninja clean
42  ninja fuzzer_corpus
43
44  # Generate a fuzzer corpus.
45  mkdir -p djxl_fuzzer_corpus
46  tools/fuzzer_corpus -q -r djxl_fuzzer_corpus
47  zip -q -j "${OUT}/djxl_fuzzer_seed_corpus.zip" djxl_fuzzer_corpus/*
48)
49
50# Build the fuzzers in release mode but force the inclusion of JXL_DASSERT()
51# checks.
52export CXXFLAGS="${CXXFLAGS} -DJXL_IS_DEBUG_BUILD=1"
53
54mkdir -p ${WORK}/libjxl-fuzzer
55cd ${WORK}/libjxl-fuzzer
56cmake \
57  "${build_args[@]}" \
58  -DJPEGXL_FUZZER_LINK_FLAGS="${LIB_FUZZING_ENGINE}" \
59  "${SRC}/libjxl"
60
61fuzzers=(
62  color_encoding_fuzzer
63  djxl_fuzzer
64  fields_fuzzer
65  icc_codec_fuzzer
66  rans_fuzzer
67)
68
69ninja clean
70ninja "${fuzzers[@]}"
71for fuzzer in "${fuzzers[@]}"; do
72  cp tools/${fuzzer} "${OUT}/"
73done
74