From 6836cc64e072237317d53588f5fff7714fded455 Mon Sep 17 00:00:00 2001 From: Jonathan Rudenberg Date: Mon, 21 May 2018 15:22:29 -0400 Subject: [PATCH] [poppler] Add poppler (#1431) * [poppler] Add poppler * cleanup * remove empty options --- projects/poppler/Dockerfile | 28 +++++++++++++++ projects/poppler/build.sh | 64 ++++++++++++++++++++++++++++++++++ projects/poppler/pdf_fuzzer.cc | 48 +++++++++++++++++++++++++ projects/poppler/project.yaml | 8 +++++ 4 files changed, 148 insertions(+) create mode 100644 projects/poppler/Dockerfile create mode 100755 projects/poppler/build.sh create mode 100644 projects/poppler/pdf_fuzzer.cc create mode 100644 projects/poppler/project.yaml diff --git a/projects/poppler/Dockerfile b/projects/poppler/Dockerfile new file mode 100644 index 000000000000..98b77ddf344f --- /dev/null +++ b/projects/poppler/Dockerfile @@ -0,0 +1,28 @@ +# 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. +# +################################################################################ + +FROM gcr.io/oss-fuzz-base/base-builder +MAINTAINER jonathan@titanous.com +RUN apt-get update && apt-get install -y make autoconf automake libtool pkg-config cmake +RUN git clone --depth 1 https://anongit.freedesktop.org/git/poppler/poppler.git +RUN git clone --depth 1 git://git.sv.nongnu.org/freetype/freetype2.git +RUN git clone --depth 1 https://github.com/mozilla/pdf.js pdf.js && \ + zip -q $SRC/pdf_fuzzer_seed_corpus.zip pdf.js/test/pdfs/*.pdf && \ + rm -rf pdf.js +ADD https://raw.githubusercontent.com/rc0r/afl-fuzz/master/dictionaries/pdf.dict $SRC/pdf_fuzzer.dict +WORKDIR $SRC +COPY *.cc poppler/fuzz/ +COPY build.sh $SRC/ diff --git a/projects/poppler/build.sh b/projects/poppler/build.sh new file mode 100755 index 000000000000..73059bf6bc36 --- /dev/null +++ b/projects/poppler/build.sh @@ -0,0 +1,64 @@ +#!/bin/bash -eu +# 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. +# +################################################################################ + +pushd $SRC/freetype2 +./autogen.sh +./configure --prefix="$WORK" --disable-shared PKG_CONFIG_PATH="$WORK/lib/pkgconfig" +make -j$(nproc) +make install + +mkdir -p $WORK/poppler +pushd $WORK/poppler +cmake $SRC/poppler \ + -DCMAKE_BUILD_TYPE=debug \ + -DBUILD_SHARED_LIBS=OFF \ + -DFONT_CONFIGURATION=generic \ + -DENABLE_DCTDECODER=none \ + -DENABLE_LIBOPENJPEG=none \ + -DENABLE_CMS=none \ + -DENABLE_LIBPNG=OFF \ + -DENABLE_ZLIB=OFF \ + -DENABLE_LIBTIFF=OFF \ + -DENABLE_LIBJPEG=OFF \ + -DENABLE_GLIB=OFF \ + -DENABLE_LIBCURL=OFF \ + -DENABLE_QT5=OFF \ + -DENABLE_UTILS=OFF \ + -DWITH_Cairo=OFF \ + -DWITH_NSS3=OFF \ + -DFREETYPE_INCLUDE_DIRS=$WORK/include/freetype2 \ + -DFREETYPE_LIBRARY=$WORK/lib +make -j$(nproc) poppler poppler-cpp + +fuzz_target=pdf_fuzzer + +pushd $SRC/poppler +$CXX $CXXFLAGS -std=c++11 -Icpp \ + fuzz/pdf_fuzzer.cc -o $OUT/$fuzz_target \ + -lFuzzingEngine $WORK/poppler/cpp/libpoppler-cpp.a $WORK/poppler/libpoppler.a $WORK/lib/libfreetype.a + +mv $SRC/{*.zip,*.dict} $OUT + +if [ ! -f "${OUT}/${fuzz_target}_seed_corpus.zip" ]; then + echo "missing seed corpus" + exit 1 +fi + +if [ ! -f "${OUT}/${fuzz_target}.dict" ]; then + echo "missing dictionary" + exit 1 +fi diff --git a/projects/poppler/pdf_fuzzer.cc b/projects/poppler/pdf_fuzzer.cc new file mode 100644 index 000000000000..93ba5d144224 --- /dev/null +++ b/projects/poppler/pdf_fuzzer.cc @@ -0,0 +1,48 @@ +/* +# 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. +# +################################################################################ +*/ + +#include + +#include +#include +#include +#include + +static void nop_func(const std::string& msg, void*) {}; + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { + poppler::set_debug_error_function(nop_func, nullptr); + + poppler::document *doc = poppler::document::load_from_raw_data((const char *)data, size); + if (!doc) { + return 0; + } + + poppler::page_renderer r; + for (int i = 0; i < doc->pages(); i++) { + poppler::page *p = doc->create_page(i); + if (!p) { + continue; + } + r.render_page(p); + delete p; + } + + delete doc; + return 0; +} diff --git a/projects/poppler/project.yaml b/projects/poppler/project.yaml new file mode 100644 index 000000000000..7f77915162f6 --- /dev/null +++ b/projects/poppler/project.yaml @@ -0,0 +1,8 @@ +homepage: https://poppler.freedesktop.org/ +primary_contact: tsdgeos@gmail.com +sanitizers: + - address + - memory + - undefined +auto_ccs: + - jonathan@titanous.com