From 7a59850942d5254245b555b1a69ee02da123139d Mon Sep 17 00:00:00 2001 From: Mirco Miranda Date: Sat, 21 Jun 2025 08:47:16 +0200 Subject: [PATCH 1/3] Move fuzz target and build into KImageFormat repo --- projects/kimageformats/Dockerfile | 22 +-- projects/kimageformats/build.sh | 190 ------------------------ projects/kimageformats/kimgio_fuzzer.cc | 74 --------- 3 files changed, 3 insertions(+), 283 deletions(-) delete mode 100644 projects/kimageformats/build.sh delete mode 100644 projects/kimageformats/kimgio_fuzzer.cc diff --git a/projects/kimageformats/Dockerfile b/projects/kimageformats/Dockerfile index eb4ce16e2688..02246daf83a0 100644 --- a/projects/kimageformats/Dockerfile +++ b/projects/kimageformats/Dockerfile @@ -15,24 +15,8 @@ ################################################################################ FROM gcr.io/oss-fuzz-base/base-builder -RUN apt-get update && apt-get install --yes cmake make autoconf automake autopoint libtool wget po4a ninja-build pkgconf -RUN git clone --depth 1 https://github.com/madler/zlib.git -RUN git clone --depth 1 -b v1.5.7 https://github.com/facebook/zstd.git -RUN wget https://sourceware.org/pub/bzip2/bzip2-1.0.8.tar.gz -RUN git clone https://github.com/tukaani-project/xz.git -RUN git clone --depth 1 --branch=RB-3.3 https://github.com/AcademySoftwareFoundation/openexr.git -RUN git clone --depth 1 -b master https://invent.kde.org/frameworks/extra-cmake-modules.git -RUN git clone --depth 1 --branch=dev git://code.qt.io/qt/qtbase.git -RUN git clone --depth 1 -b master https://invent.kde.org/frameworks/karchive.git RUN git clone --depth 1 -b master https://invent.kde.org/frameworks/kimageformats.git -RUN git clone --depth 1 -b v3.12.1 https://aomedia.googlesource.com/aom -RUN git clone --depth 1 -b v1.3.0 https://github.com/AOMediaCodec/libavif.git -RUN git clone --depth 1 https://github.com/strukturag/libde265.git -RUN git clone --depth 1 -b v2.5.3 https://github.com/uclouvain/openjpeg.git -RUN git clone --depth 1 https://github.com/strukturag/libheif.git -RUN git clone --depth=1 --branch v0.11.x --recursive --shallow-submodules https://github.com/libjxl/libjxl.git -RUN git clone --depth 1 https://github.com/LibRaw/LibRaw -RUN git clone --depth 1 https://github.com/mircomir/jxrlib.git -RUN git clone --depth 1 -b v2.6.0 https://github.com/cisco/openh264.git -COPY build.sh kimgio_fuzzer.cc $SRC/ +RUN $SRC/kimageformats/autotests/ossfuzz/prepare_build.sh +RUN cp $SRC/kimageformats/autotests/ossfuzz/build_fuzzers.sh $SRC/build.sh + WORKDIR $SRC/kimageformats diff --git a/projects/kimageformats/build.sh b/projects/kimageformats/build.sh deleted file mode 100644 index 30bf5a548cc7..000000000000 --- a/projects/kimageformats/build.sh +++ /dev/null @@ -1,190 +0,0 @@ -#!/bin/bash -eu -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -################################################################################ - -# build zstd -cd $SRC/zstd -cmake -S build/cmake -DBUILD_SHARED_LIBS=OFF -make install -j$(nproc) - -# Build zlib -cd $SRC/zlib -./configure --static -make install -j$(nproc) - -# Build bzip2 -# Inspired from ../bzip2/build -cd $SRC -tar xzf bzip2-*.tar.gz && rm -f bzip2-*.tar.gz -cd bzip2-* -SRCL=(blocksort.o huffman.o crctable.o randtable.o compress.o decompress.o bzlib.o) - -for source in ${SRCL[@]}; do - name=$(basename $source .o) - $CC $CFLAGS -c ${name}.c -done -rm -f libbz2.a -ar cq libbz2.a ${SRCL[@]} -cp -f bzlib.h /usr/local/include -cp -f libbz2.a /usr/local/lib - -# Build xz -export ORIG_CFLAGS="${CFLAGS}" -export ORIG_CXXFLAGS="${CXXFLAGS}" -unset CFLAGS -unset CXXFLAGS -cd $SRC/xz -./autogen.sh --no-po4a --no-doxygen -./configure --enable-static --disable-debug --disable-shared --disable-xz --disable-xzdec --disable-lzmainfo -make install -j$(nproc) -export CFLAGS="${ORIG_CFLAGS}" -export CXXFLAGS="${ORIG_CXXFLAGS}" - -# Build qt -cd $SRC/qtbase -./configure -no-glib -qt-libpng -qt-pcre -opensource -confirm-license -static -no-opengl -no-icu -platform linux-clang-libc++ -debug -prefix /usr -no-feature-widgets -no-feature-sql -no-feature-network -no-feature-xml -no-feature-dbus -no-feature-printsupport -cmake --build . --parallel $(nproc) -cmake --install . - -# Build extra-cmake-modules -cd $SRC/extra-cmake-modules -cmake . -DBUILD_TESTING=OFF -make install -j$(nproc) - -cd $SRC/karchive -rm -rf poqm -cmake . -DBUILD_SHARED_LIBS=OFF -DBUILD_TESTING=OFF -DCMAKE_INSTALL_PREFIX=/usr/local -make install -j$(nproc) - -# Build JXRlib -cd $SRC/jxrlib -make -j$(nproc) - -# Build LibRaw -cd $SRC/LibRaw -TMP_CFLAGS=$CFLAGS -TMP_CXXFLAGS=$CXXFLAGS -CFLAGS="$CFLAGS -fno-sanitize=function,vptr" -CXXFLAGS="$CXXFLAGS -fno-sanitize=function,vptr" -autoreconf --install -./configure --disable-examples -make -j$(nproc) -make install -j$(nproc) -CFLAGS=$TMP_CFLAGS -CXXFLAGS=$TMP_CXXFLAGS - - -# Build aom -cd $SRC/aom -mkdir build.libavif -cd build.libavif -extra_libaom_flags='-DAOM_MAX_ALLOCABLE_MEMORY=536870912 -DDO_RANGE_CHECK_CLAMP=1' -cmake -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}" .. -make -j$(nproc) -make install -j$(nproc) - -# Build libavif -cd $SRC/libavif -ln -s "$SRC/aom" "$SRC/libavif/ext/" -mkdir build -cd build -CFLAGS="$CFLAGS -fPIC" cmake -DBUILD_SHARED_LIBS=OFF -DAVIF_ENABLE_WERROR=OFF -DAVIF_CODEC_AOM=LOCAL -DAVIF_LIBYUV=OFF .. -make -j$(nproc) - -# Build libde265 -cd $SRC/libde265 -cmake -DBUILD_SHARED_LIBS=OFF -DDISABLE_SSE=ON . -make -j$(nproc) -make install -j$(nproc) - -# Build openjpeg -cd $SRC/openjpeg -mkdir build -cd build -cmake -DBUILD_SHARED_LIBS=OFF -DBUILD_STATIC_LIBS=ON -DBUILD_CODEC=OFF .. -make -j$(nproc) -make install -j$(nproc) - -# build openh264 -cd $SRC/openh264 -make USE_ASM=No BUILDTYPE=Debug install-static -j$(nproc) - -# Build openexr -cd $SRC/openexr -mkdir _build -cd _build -cmake -DBUILD_SHARED_LIBS=OFF .. -make -j$(nproc) -make install -j$(nproc) - -# Build libheif -cd $SRC/libheif -#Reduce max width and height to avoid allocating too much memory -sed -i "s/static const int MAX_IMAGE_WIDTH = 32768;/static const int MAX_IMAGE_WIDTH = 8192;/g" libheif/security_limits.h -sed -i "s/static const int MAX_IMAGE_HEIGHT = 32768;/static const int MAX_IMAGE_HEIGHT = 8192;/g" libheif/security_limits.h -mkdir build -cd build -cmake -DBUILD_SHARED_LIBS=OFF -DENABLE_PLUGIN_LOADING=OFF -DWITH_DAV1D=OFF -DWITH_EXAMPLES=OFF -DWITH_LIBDE265=ON -DWITH_RAV1E=OFF -DWITH_RAV1E_PLUGIN=OFF -DWITH_SvtEnc=OFF -DWITH_SvtEnc_PLUGIN=OFF -DWITH_X265=OFF -DWITH_OpenJPEG_DECODER=ON -DWITH_OpenH264_DECODER=ON .. -make -j$(nproc) -make install -j$(nproc) - -# Build libjxl -cd $SRC/libjxl -mkdir build -cd build -CXXFLAGS="$CXXFLAGS -DHWY_COMPILE_ONLY_SCALAR" cmake -DBUILD_SHARED_LIBS=OFF -DBUILD_TESTING=OFF -DJPEGXL_ENABLE_BENCHMARK=OFF -DJPEGXL_ENABLE_DOXYGEN=OFF -DJPEGXL_ENABLE_EXAMPLES=OFF -DJPEGXL_ENABLE_JNI=OFF -DJPEGXL_ENABLE_JPEGLI=OFF -DJPEGXL_ENABLE_JPEGLI_LIBJPEG=OFF -DJPEGXL_ENABLE_MANPAGES=OFF -DJPEGXL_ENABLE_OPENEXR=OFF -DJPEGXL_ENABLE_PLUGINS=OFF -DJPEGXL_ENABLE_SJPEG=OFF -DJPEGXL_ENABLE_SKCMS=ON -DJPEGXL_ENABLE_TCMALLOC=OFF -DJPEGXL_ENABLE_TOOLS=OFF -DJPEGXL_ENABLE_FUZZERS=OFF .. -make -j$(nproc) jxl jxl_cms jxl_threads - -cd $SRC/kimageformats -HANDLER_TYPES="ANIHandler ani - QAVIFHandler avif - QDDSHandler dds - EXRHandler exr - HDRHandler hdr - HEIFHandler heif - IFFHandler iff - JP2Handler jp2 - QJpegXLHandler jxl - JXRHandler jxr - KraHandler kra - OraHandler ora - PCXHandler pcx - PFMHandler pfm - SoftimagePICHandler pic - PSDHandler psd - PXRHandler pxr - QOIHandler qoi - RASHandler ras - RAWHandler raw - RGBHandler rgb - ScitexHandler sct - TGAHandler tga - XCFHandler xcf" - -echo "$HANDLER_TYPES" | while read class format; do -( - fuzz_target_name=kimgio_${format}_fuzzer - - /usr/libexec/moc $SRC/kimageformats/src/imageformats/$format.cpp -o $format.moc - header=`ls $SRC/kimageformats/src/imageformats/$format*.h` - /usr/libexec/moc $header -o moc_`basename $header .h`.cpp - $CXX $CXXFLAGS -fPIC -DHANDLER=$class -std=c++17 $SRC/kimgio_fuzzer.cc $SRC/kimageformats/src/imageformats/$format.cpp $SRC/kimageformats/src/imageformats/scanlineconverter.cpp $SRC/kimageformats/src/imageformats/microexif.cpp $SRC/kimageformats/src/imageformats/chunks.cpp -o $OUT/$fuzz_target_name -DJXL_STATIC_DEFINE -DJXL_THREADS_STATIC_DEFINE -DJXL_CMS_STATIC_DEFINE -DINITGUID -I $SRC/kimageformats/src/imageformats/ -I $SRC/libavif/include/ -I $SRC/libjxl/build/lib/include/ -I $SRC/libjxl/lib/include/ -I /usr/local/include/OpenEXR/ -I /usr/local/include/KF6/KArchive/ -I /usr/local/include/openjpeg-2.5 -I /usr/local/include/Imath -I $SRC/jxrlib/common/include -I $SRC/jxrlib/jxrgluelib -I $SRC/jxrlib/image/sys -I /usr/include/QtCore/ -I /usr/include/QtGui/ -I . $SRC/libavif/build/libavif.a /usr/local/lib/libheif.a /usr/local/lib/libde265.a /usr/local/lib/libopenh264.a $SRC/aom/build.libavif/libaom.a $SRC/libjxl/build/lib/libjxl_threads.a $SRC/libjxl/build/lib/libjxl.a $SRC/libjxl/build/lib/libjxl_cms.a $SRC/libjxl/build/third_party/highway/libhwy.a $SRC/libjxl/build/third_party/brotli/libbrotlidec.a $SRC/libjxl/build/third_party/brotli/libbrotlienc.a $SRC/libjxl/build/third_party/brotli/libbrotlicommon.a -lQt6Gui -lQt6Core -lQt6BundledLibpng -lQt6BundledHarfbuzz -lm -lQt6BundledPcre2 -ldl -lpthread $LIB_FUZZING_ENGINE /usr/local/lib/libz.a -lKF6Archive /usr/local/lib/libz.a /usr/local/lib/libraw.a /usr/local/lib/libOpenEXR-3_3.a /usr/local/lib/libIex-3_3.a /usr/local/lib/libImath-3_1.a /usr/local/lib/libIlmThread-3_3.a /usr/local/lib/libOpenEXRCore-3_3.a /usr/local/lib/libOpenEXRUtil-3_3.a /usr/local/lib/libopenjp2.a /usr/local/lib/libzstd.a $SRC/jxrlib/build/libjxrglue.a $SRC/jxrlib/build/libjpegxr.a -llzma /usr/local/lib/libbz2.a -lclang_rt.builtins - - # -lclang_rt.builtins in the previous line is a temporary workaround to avoid a linker error "undefined reference to __truncsfhf2". Investigate why this is needed here, but not anywhere else, and possibly remove it. - - find . -name "*.${format}" | zip -q $OUT/${fuzz_target_name}_seed_corpus.zip -@ -) -done diff --git a/projects/kimageformats/kimgio_fuzzer.cc b/projects/kimageformats/kimgio_fuzzer.cc deleted file mode 100644 index c029f118b5e1..000000000000 --- a/projects/kimageformats/kimgio_fuzzer.cc +++ /dev/null @@ -1,74 +0,0 @@ -/* -# Copyright 2018 Google Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -################################################################################ -*/ - -/* - Usage: - python infra/helper.py build_image kimageformats - python infra/helper.py build_fuzzers --sanitizer undefined|address|memory kimageformats - python infra/helper.py run_fuzzer kimageformats kimgio_[ani|avif|dds|exr|hdr|heif|iff|jp2|jxl|jxr|kra|ora|pcx|pfm|pic|psd|pxr|qoi|ras|raw|rgb|sct|tga|xcf]_fuzzer -*/ - - -#include -#include -#include - -#include "ani_p.h" -#include "avif_p.h" -#include "dds_p.h" -#include "exr_p.h" -#include "hdr_p.h" -#include "heif_p.h" -#include "iff_p.h" -#include "jp2_p.h" -#include "jxl_p.h" -#include "jxr_p.h" -#include "kra.h" -#include "ora.h" -#include "qoi_p.h" -#include "pcx_p.h" -#include "pfm_p.h" -#include "pic_p.h" -#include "psd_p.h" -#include "pxr_p.h" -#include "ras_p.h" -#include "raw_p.h" -#include "rgb_p.h" -#include "sct_p.h" -#include "tga_p.h" -#include "xcf_p.h" - -extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) -{ - int argc = 0; - QCoreApplication a(argc, nullptr); - - QImageIOHandler* handler = new HANDLER(); - - QImage i; - QBuffer b; - b.setData((const char *)data, size); - b.open(QIODevice::ReadOnly); - handler->setDevice(&b); - handler->canRead(); - handler->read(&i); - - delete handler; - - return 0; -} From 1fbdb0c2997e752dff8e60c5368bce457291ba3a Mon Sep 17 00:00:00 2001 From: Mirco Miranda Date: Sat, 13 Sep 2025 13:55:11 +0200 Subject: [PATCH 2/3] Fix libjxl compilation --- projects/kimageformats/Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/projects/kimageformats/Dockerfile b/projects/kimageformats/Dockerfile index 02246daf83a0..2a0d37f92b64 100644 --- a/projects/kimageformats/Dockerfile +++ b/projects/kimageformats/Dockerfile @@ -14,6 +14,7 @@ # ################################################################################ +# Todo: unpin to support llvm 22 FROM gcr.io/oss-fuzz-base/base-builder RUN git clone --depth 1 -b master https://invent.kde.org/frameworks/kimageformats.git RUN $SRC/kimageformats/autotests/ossfuzz/prepare_build.sh From 8d2188d0bd948ec2ec0b8069348b84cee3e49928 Mon Sep 17 00:00:00 2001 From: Mirco Miranda Date: Sat, 13 Sep 2025 14:20:31 +0200 Subject: [PATCH 3/3] Pin d34d94 --- projects/kimageformats/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/kimageformats/Dockerfile b/projects/kimageformats/Dockerfile index 2a0d37f92b64..7c1a08e89cf5 100644 --- a/projects/kimageformats/Dockerfile +++ b/projects/kimageformats/Dockerfile @@ -15,7 +15,7 @@ ################################################################################ # Todo: unpin to support llvm 22 -FROM gcr.io/oss-fuzz-base/base-builder +FROM gcr.io/oss-fuzz-base/base-builder@sha256:d34b94e3cf868e49d2928c76ddba41fd4154907a1a381b3a263fafffb7c3dce0 RUN git clone --depth 1 -b master https://invent.kde.org/frameworks/kimageformats.git RUN $SRC/kimageformats/autotests/ossfuzz/prepare_build.sh RUN cp $SRC/kimageformats/autotests/ossfuzz/build_fuzzers.sh $SRC/build.sh