Skip to content

Commit

Permalink
vlc: use official repo + add seeds and dicts + add demuxers (#13010)
Browse files Browse the repository at this point in the history
- Remove useless vlc-demux-libfuzzer output target
- Use the official VideoLAN/vlc repository
- Add seeds and dicts: create one output target per format
- Add mkv, ogg, xml support
  • Loading branch information
tguillem authored Feb 10, 2025
1 parent bfa03c9 commit f62a81f
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 9 deletions.
5 changes: 3 additions & 2 deletions projects/vlc/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

FROM gcr.io/oss-fuzz-base/base-builder
RUN apt-get update && apt-get install -y make autoconf automake libtool \
pkg-config cmake flex bison gettext libglu1-mesa-dev
RUN git clone --depth 1 https://github.com/videolan/vlc vlc
pkg-config cmake flex bison gettext libglu1-mesa-dev ninja-build
RUN git clone --depth 1 https://code.videolan.org/videolan/vlc.git vlc
RUN git clone --depth 1 https://code.videolan.org/VideoLAN.org/vlc-fuzz-corpus.git vlc/fuzz-corpus
WORKDIR vlc
COPY build.sh $SRC/
82 changes: 75 additions & 7 deletions projects/vlc/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,58 @@
#
################################################################################

# Build dependencies without instrumentation
CFLAGS_SAVE="$CFLAGS"
CXXFLAGS_SAVE="$CXXFLAGS"
unset CFLAGS
unset CXXFLAGS
export AFL_NOOPT=1

# But we need libc++
export CXXFLAGS="-stdlib=libc++"

mkdir contrib/contrib-build
cd contrib/contrib-build
../bootstrap

make V=1 -j$(nproc) \
.matroska \
.ogg \
.libxml2

cd ../../

# Resume instrumentation
export CFLAGS="${CFLAGS_SAVE}"
export CXXFLAGS="${CXXFLAGS_SAVE}"
unset AFL_NOOPT

# Use OSS-Fuzz environment rather than hardcoded setup.
sed -i 's/-fsanitize-coverage=trace-pc-guard//g' ./configure.ac
sed -i 's/-fsanitize-coverage=trace-cmp//g' ./configure.ac
sed -i 's/-fsanitize-coverage=trace-pc//g' ./configure.ac
sed -i 's/-lFuzzer//g' ./configure.ac

# In order to build statically we avoid libxml and ogg plugins.
# Use default -lc++
sed -i 's/-lstdc++ //g' ./configure.ac
sed -i 's/-lstdc++/$(NULL)/g' ./test/Makefile.am

sed -i 's/..\/..\/lib\/libvlc_internal.h/lib\/libvlc_internal.h/g' ./test/src/input/decoder.c
sed -i 's/..\/modules\/libxml_plugin.la//g' ./test/Makefile.am
sed -i 's/..\/modules\/libogg_plugin.la//g' ./test/Makefile.am
sed -i 's/f(misc_xml_xml)//g' ./test/src/input/demux-run.c
sed -i 's/f(demux_ogg)//g' ./test/src/input/demux-run.c

# clang is used to link the binary since there are no cpp sources (but we have
# cpp modules), force clang++ usage
touch ./test/dummy.cpp

# Rework implicit RULEs so that the final sed add dummy.cpp
RULE=vlc_demux_libfuzzer
RULE_SOURCES="${RULE}_SOURCES = vlc-demux-libfuzzer.c"
sed -i "s/${RULE}_LDADD/${RULE_SOURCES}\n${RULE}_LDADD/g" ./test/Makefile.am
RULE=vlc_demux_run
RULE_SOURCES="${RULE}_SOURCES = vlc-demux-run.c"
sed -i "s/${RULE}_LDADD/${RULE_SOURCES}\n${RULE}_LDADD/g" ./test/Makefile.am

# Add dummy.cpp to all rules
sed -i 's/_SOURCES = /_SOURCES = dummy.cpp /g' ./test/Makefile.am

# Ensure that we compile with the correct link flags.
RULE="vlc_demux_libfuzzer_LDADD"
Expand All @@ -38,7 +78,9 @@ FUZZ_LDFLAGS="vlc_demux_dec_libfuzzer_LDFLAGS=\${LIB_FUZZING_ENGINE}"
sed -i "s/${RULE}/${FUZZ_LDFLAGS}\n${RULE}/g" ./test/Makefile.am

./bootstrap
./configure --disable-ogg --disable-oggspots --disable-libxml2 --disable-lua \

./configure --disable-lua \
--disable-nls \
--disable-shared \
--enable-static \
--enable-vlc=no \
Expand All @@ -50,4 +92,30 @@ sed -i "s/${RULE}/${FUZZ_LDFLAGS}\n${RULE}/g" ./test/Makefile.am
--with-libfuzzer
make V=1 -j$(nproc)
cp ./test/vlc-demux-dec-libfuzzer $OUT/
cp ./test/vlc-demux-libfuzzer $OUT/

for i in fuzz-corpus/seeds/* fuzz-corpus/dictionaries/*.dict
do
target=`basename "$i" .dict`
outfile="$OUT/vlc-demux-dec-$target-libfuzzer"

# Copy dict or seeds
if [ -f "$i" ]; then
cp "$i" "${outfile}.dict"
else
zip -jr "${outfile}_seed_corpus.zip" "$i"/*
fi

# may be already created by seeds
if [ -f "$outfile" ];then
continue;
fi

# Create a binary wrapper with correct env variables
cat <<EOF > "$outfile"
#!/bin/sh
export VLC_TARGET=$target
exec ./vlc-demux-dec-libfuzzer "\$@"
EOF

chmod +x "$outfile"
done

0 comments on commit f62a81f

Please sign in to comment.