1#!/bin/bash -eu 2# Copyright 2020 Google LLC 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 18cd $SRC 19cd zlib 20./configure --static 21make install -j$(nproc) 22 23cd $SRC 24cd libzip 25cmake . -DBUILD_SHARED_LIBS=OFF 26make install -j$(nproc) 27 28cd $SRC 29cd extra-cmake-modules 30cmake . 31make install -j$(nproc) 32 33cd $SRC 34cd qtbase 35# add the flags to Qt build too 36sed -i -e "s/QMAKE_CXXFLAGS += -stdlib=libc++/QMAKE_CXXFLAGS += -stdlib=libc++ $CXXFLAGS\nQMAKE_CFLAGS += $CFLAGS/g" mkspecs/linux-clang-libc++/qmake.conf 37sed -i -e "s/QMAKE_LFLAGS += -stdlib=libc++/QMAKE_LFLAGS += -stdlib=libc++ -lpthread $CXXFLAGS/g" mkspecs/linux-clang-libc++/qmake.conf 38# disable sanitize=vptr for harfbuzz since it compiles without rtti 39sed -i -e "s/TARGET = qtharfbuzz/TARGET = qtharfbuzz\nQMAKE_CXXFLAGS += -fno-sanitize=vptr/g" src/3rdparty/harfbuzz-ng/harfbuzz-ng.pro 40# make qmake compile faster 41sed -i -e "s/MAKE\")/MAKE\" -j$(nproc))/g" configure 42./configure --glib=no --libpng=qt -opensource -confirm-license -static -no-opengl -no-icu -platform linux-clang-libc++ -v 43cd src 44../bin/qmake -o Makefile src.pro 45make sub-gui -j$(nproc) 46 47cd $SRC 48cd karchive 49cmake . -DBUILD_SHARED_LIBS=OFF -DQt5Core_DIR=$SRC/qtbase/lib/cmake/Qt5Core/ -DBUILD_TESTING=OFF 50make install -j$(nproc) 51 52cd $SRC 53cd aom 54mkdir build.libavif 55cd build.libavif 56extra_libaom_flags='-DAOM_MAX_ALLOCABLE_MEMORY=536870912 -DDO_RANGE_CHECK_CLAMP=1' 57cmake -DBUILD_SHARED_LIBS=0 -DENABLE_DOCS=0 -DENABLE_EXAMPLES=0 -DENABLE_TESTDATA=0 -DENABLE_TESTS=0 -DENABLE_TOOLS=0 -DCONFIG_PIC=1 -DAOM_TARGET_CPU=generic -DCONFIG_SIZE_LIMIT=1 -DDECODE_HEIGHT_LIMIT=12288 -DDECODE_WIDTH_LIMIT=12288 -DAOM_EXTRA_C_FLAGS="${extra_libaom_flags}" -DAOM_EXTRA_CXX_FLAGS="${extra_libaom_flags}" .. 58make -j$(nproc) 59make install -j$(nproc) 60 61cd $SRC 62ln -s "$SRC/aom" "$SRC/libavif/ext/" 63cd libavif 64mkdir build 65cd build 66CFLAGS="$CFLAGS -fPIC" cmake -DBUILD_SHARED_LIBS=OFF -DAVIF_ENABLE_WERROR=OFF -DAVIF_CODEC_AOM=ON -DAVIF_LOCAL_AOM=ON .. 67make -j$(nproc) 68 69cd $SRC 70cd libde265 71cmake -DBUILD_SHARED_LIBS=OFF -DDISABLE_SSE=ON . 72make -j$(nproc) 73make install -j$(nproc) 74 75cd $SRC 76cd libheif 77#Reduce max width and height to avoid allocating too much memory 78sed -i "s/static const int MAX_IMAGE_WIDTH = 32768;/static const int MAX_IMAGE_WIDTH = 8192;/g" libheif/heif_limits.h 79sed -i "s/static const int MAX_IMAGE_HEIGHT = 32768;/static const int MAX_IMAGE_HEIGHT = 8192;/g" libheif/heif_limits.h 80mkdir build 81cd build 82cmake -DBUILD_SHARED_LIBS=OFF -DWITH_AOM=ON -DWITH_DAV1D=OFF -DWITH_EXAMPLES=OFF -DWITH_LIBDE265=ON -DWITH_RAV1E=OFF -DWITH_X265=OFF .. 83make -j$(nproc) 84make install -j$(nproc) 85 86cd $SRC 87cd kimageformats 88HANDLER_TYPES="ANIHandler ani 89 QAVIFHandler avif 90 HEIFHandler heif 91 KraHandler kra 92 OraHandler ora 93 PCXHandler pcx 94 SoftimagePICHandler pic 95 PSDHandler psd 96 RASHandler ras 97 RGBHandler rgb 98 TGAHandler tga 99 XCFHandler xcf" 100 101echo "$HANDLER_TYPES" | while read class format; do 102( 103 fuzz_target_name=kimgio_${format}_fuzzer 104 105 $SRC/qtbase/bin/moc $SRC/kimageformats/src/imageformats/$format.cpp -o $format.moc 106 $CXX $CXXFLAGS -fPIC -DHANDLER=$class -std=c++14 $SRC/kimgio_fuzzer.cc $SRC/kimageformats/src/imageformats/$format.cpp -o $OUT/$fuzz_target_name -I $SRC/qtbase/include/QtCore/ -I $SRC/qtbase/include/ -I $SRC/qtbase/include//QtGui -I $SRC/kimageformats/src/imageformats/ -I $SRC/karchive/src/ -I $SRC/qtbase/mkspecs/linux-clang-libc++/ -I $SRC/libavif/include/ -I . -L $SRC/qtbase/lib $SRC/libavif/build/libavif.a /usr/local/lib/libheif.a /usr/local/lib/liblibde265.a $SRC/aom/build.libavif/libaom.a -lQt5Gui -lQt5Core -lqtlibpng -lqtharfbuzz -lm -lqtpcre2 -ldl -lpthread $LIB_FUZZING_ENGINE /usr/local/lib/libzip.a /usr/local/lib/libz.a -lKF5Archive /usr/local/lib/libz.a 107 108 find . -name "*.${format}" | zip -q $OUT/${fuzz_target_name}_seed_corpus.zip -@ 109) 110done 111