Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions projects/cairo/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,31 @@
# limitations under the License.
#
################################################################################
FROM gcr.io/oss-fuzz-base/base-builder
FROM gcr.io/oss-fuzz-base/base-builder:ubuntu-24-04
RUN apt-get update && \
apt-get install -y python3-pip gtk-doc-tools libffi-dev autotools-dev libtool gperf
RUN pip3 install -U meson==1.4.0 ninja packaging
RUN pip3 install -U meson==1.6.0 ninja packaging

RUN git clone --depth 1 git://git.sv.nongnu.org/freetype/freetype2.git
RUN git clone --depth 1 https://gitlab.gnome.org/GNOME/glib
RUN git clone --depth 1 https://gitlab.freedesktop.org/cairo/cairo.git && \
zip -q $SRC/cairo_seed_corpus.zip $SRC/cairo/test/reference/* && \
zip -q $SRC/svg-render-fuzzer_seed_corpus.zip $SRC/cairo/test/svg/*.svg
RUN cd cairo && meson subprojects download

# pre-install all dependencies into /deps to exclude them from fuzz-introspector
RUN mkdir /deps && cd cairo && \
meson subprojects foreach \
meson setup \
--prefix=/deps \
--libdir=lib \
--default-library=static \
-Db_lundef=false \
_builddir && \
meson subprojects foreach \
ninja -C _builddir && \
meson subprojects foreach \
ninja -C _builddir install
# *convince* fuzz-introspector not to analyze all harnesses in subprojects
RUN rm -rf cairo/subprojects/*

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this because the FUZZ_INTROSPECTOR_CONFIG set in build.sh did not prevent fuzz-introspector from analyzing the subprojects folder.


ADD https://raw.githubusercontent.com/google/fuzzing/master/dictionaries/png.dict $SRC/cairo.dict
ADD https://raw.githubusercontent.com/google/fuzzing/master/dictionaries/svg.dict $SRC/svg-render-fuzzer.dict
Expand Down
65 changes: 37 additions & 28 deletions projects/cairo/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,47 +14,53 @@
# limitations under the License.
#
################################################################################

# For fuzz-introspector, exclude all external code from reports
export FUZZ_INTROSPECTOR_CONFIG=$SRC/fuzz_introspector_exclusion.config
cat > $FUZZ_INTROSPECTOR_CONFIG <<EOF
FILES_TO_AVOID
subprojects
EOF

PREFIX=$WORK/prefix
mkdir -p $PREFIX
CAIRO_DEPS=/deps

export PKG_CONFIG="`which pkg-config` --static"
export PKG_CONFIG_PATH=$PREFIX/lib/pkgconfig
export PATH=$PREFIX/bin:$PATH

BUILD=$WORK/build
export PKG_CONFIG_PATH=$PREFIX/lib/pkgconfig:$CAIRO_DEPS/lib/pkgconfig
export PATH=$PREFIX/bin:$CAIRO_DEPS/bin:$PATH

# BUILD=$WORK/build
rm -rf $WORK/*
rm -rf $BUILD
mkdir -p $BUILD

# Build glib
pushd $SRC/glib/
meson \
setup \
--prefix=$PREFIX \
--libdir=lib \
--default-library=static \
-Db_lundef=false \
-Doss_fuzz=enabled \
-Dlibmount=disabled \
_builddir
ninja -C _builddir
ninja -C _builddir install
popd
# workaround: tell meson to use gold on fuzz-introspector builds
# https://github.com/google/oss-fuzz/pull/7583#issuecomment-1104011067
if [[ "$SANITIZER" == introspector ]]; then
# -fuse-ld=gold can't be passed via CFLAGS/CXXFLAGS/LDFLAGS due to
# https://github.com/mesonbuild/meson/issues/6377 and
# https://github.com/mesonbuild/meson/issues/6377#issuecomment-575977919
MESON_CFLAGS="${CFLAGS//-fuse-ld=gold/ }"
MESON_CXXFLAGS="${CXXFLAGS//-fuse-ld=gold/ }"
MESON_OPTIONS="-Db_lto=true"

pushd $SRC/freetype2
./autogen.sh
./configure --prefix="$PREFIX" --disable-shared PKG_CONFIG_PATH="$PKG_CONFIG_PATH"
make -j$(nproc)
make install
export CC_LD=gold
export CXX_LD=gold
else
MESON_CFLAGS=$CFLAGS
MESON_CXXFLAGS=$CXXFLAGS
MESON_OPTIONS=""
fi

# Build cairo
pushd $SRC/cairo
CFLAGS="-DDEBUG_SVG_RENDER $CFLAGS" meson \
CFLAGS="-DDEBUG_SVG_RENDER $MESON_CFLAGS" \
CXXFLAGS=$MESON_CXXFLAGS meson \
setup \
--prefix=$PREFIX \
--libdir=lib \
--default-library=static \
-Db_lundef=false \
--wrap-mode=nofallback \
$MESON_OPTIONS \
_builddir
ninja -C _builddir
ninja -C _builddir install
Expand All @@ -75,7 +81,7 @@ fi
PREDEPS_LDFLAGS="-Wl,-Bdynamic -ldl -lm -lc -pthread -lrt -lpthread"
DEPS="gmodule-2.0 glib-2.0 gio-2.0 gobject-2.0 freetype2 cairo cairo-gobject cairo-script-interpreter"
BUILD_CFLAGS="$CFLAGS `pkg-config --static --cflags $DEPS` -I$SRC/fuzz"
BUILD_LDFLAGS="-Wl,-static `pkg-config --static --libs $DEPS`"
BUILD_LDFLAGS="`pkg-config --static --libs $DEPS`"

fuzzers=$(find $SRC/fuzz/ -name "*_fuzzer.c")
for f in $fuzzers ; do
Expand Down Expand Up @@ -104,3 +110,6 @@ for f in $SRC/cairo/test/svg/fuzzer/svg-render-fuzzer.c ; do
$LIB_FUZZING_ENGINE \
-Wl,-Bdynamic
done

# copy deps into $OUT so fuzz-introspector can see the header files
rsync -avr $CAIRO_DEPS/ $OUT/deps
1 change: 1 addition & 0 deletions projects/cairo/project.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ fuzzing_engines:
- honggfuzz
- libfuzzer

base_os_version: ubuntu-24-04