Debian Codegraph @

compat/libpng/contrib/oss-fuzz/build.sh

raw symbols SCIP
1 #!/bin/bash -eu
2
3 # Copyright 2017-2018 Glenn Randers-Pehrson
4 # Copyright 2016 Google Inc.
5 #
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
9 #
10 # http://www.apache.org/licenses/LICENSE-2.0
11 #
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17 #
18 # Revisions by Glenn Randers-Pehrson, 2017:
19 # 1. Build only the library, not the tools (changed "make -j$(nproc) all" to
20 # "make -j$(nproc) libpng16.la").
21 # 2. Disabled WARNING and WRITE options in pnglibconf.dfa.
22 # 3. Build zlib alongside libpng
23 ################################################################################
24
25 # Disable logging via library build configuration control.
26 cat scripts/pnglibconf.dfa | \
27 sed -e "s/option STDIO/option STDIO disabled/" \
28 -e "s/option WARNING /option WARNING disabled/" \
29 -e "s/option WRITE enables WRITE_INT_FUNCTIONS/option WRITE disabled/" \
30 > scripts/pnglibconf.dfa.temp
31 mv scripts/pnglibconf.dfa.temp scripts/pnglibconf.dfa
32
33 # build the libpng library.
34 autoreconf -f -i
35 ./configure --with-libpng-prefix=OSS_FUZZ_
36 make -j$(nproc) clean
37 make -j$(nproc) libpng16.la
38
39 for f in libpng_read_fuzzer \
40 libpng_colormap_fuzzer \
41 libpng_readapi_fuzzer \
42 libpng_transformations_fuzzer;
43 do
44 # build libpng_read_fuzzer.
45 $CXX $CXXFLAGS -std=c++11 -I. \
46 $SRC/libpng/contrib/oss-fuzz/${f}.cc \
47 -o $OUT/${f} \
48 -lFuzzingEngine .libs/libpng16.a -lz
49
50 # only libfuzzer can run the nalloc targets
51 if test "x$FUZZING_ENGINE" == 'xlibfuzzer'
52 then
53
54 # wrapper script to duplicate target, run with env var NALLOC_FREQ=32
55 # having a separate target with allocations failures
56 cat << EOF > $OUT/${f}_nalloc
57 #!/bin/sh
58 # LLVMFuzzerTestOneInput for fuzzer detection.
59 this_dir=\$(dirname "\$0")
60 NALLOC_FREQ=32 \$this_dir/${f} \$@
61 EOF
62 chmod +x $OUT/${f}_nalloc
63
64 # add seed corpus.
65 find $SRC/libpng -name "*.png" | \
66 xargs zip $OUT/${f}_seed_corpus.zip
67
68 cp $SRC/libpng/contrib/oss-fuzz/png.dict $OUT/${f}.dict
69 done
70
71 cp $SRC/libpng/contrib/oss-fuzz/*.dict \
72 $SRC/libpng/contrib/oss-fuzz/*.options $OUT/
73
74 fi
75 # end