Skip to content

Commit

Permalink
[poppler] Add poppler (#1431)
Browse files Browse the repository at this point in the history
* [poppler] Add poppler

* cleanup

* remove empty options
  • Loading branch information
titanous authored and inferno-chromium committed May 21, 2018
1 parent caddf9a commit 6836cc6
Show file tree
Hide file tree
Showing 4 changed files with 148 additions and 0 deletions.
28 changes: 28 additions & 0 deletions projects/poppler/Dockerfile
Original file line number Diff line number Diff line change
@@ -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/
64 changes: 64 additions & 0 deletions projects/poppler/build.sh
Original file line number Diff line number Diff line change
@@ -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
48 changes: 48 additions & 0 deletions projects/poppler/pdf_fuzzer.cc
Original file line number Diff line number Diff line change
@@ -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 <cstdint>

#include <poppler-global.h>
#include <poppler-document.h>
#include <poppler-page.h>
#include <poppler-page-renderer.h>

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;
}
8 changes: 8 additions & 0 deletions projects/poppler/project.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
homepage: https://poppler.freedesktop.org/
primary_contact: tsdgeos@gmail.com
sanitizers:
- address
- memory
- undefined
auto_ccs:
- jonathan@titanous.com

0 comments on commit 6836cc6

Please sign in to comment.