From 7040f91b3ce642bc1b2915cc1f8c7bee46b7cbb1 Mon Sep 17 00:00:00 2001 From: Paul Kehrer Date: Tue, 3 Apr 2018 21:51:30 -0500 Subject: [PATCH] [libexif] add libexif (#1285) * add libexif * make the fuzzer parse a bit more * review feedback, be less confusing with Data and data vars * added primary contact --- projects/libexif/Dockerfile | 23 +++++++++++++++++++ projects/libexif/build.sh | 29 ++++++++++++++++++++++++ projects/libexif/exif_loader_fuzzer.cc | 31 ++++++++++++++++++++++++++ projects/libexif/project.yaml | 7 ++++++ 4 files changed, 90 insertions(+) create mode 100644 projects/libexif/Dockerfile create mode 100755 projects/libexif/build.sh create mode 100644 projects/libexif/exif_loader_fuzzer.cc create mode 100644 projects/libexif/project.yaml diff --git a/projects/libexif/Dockerfile b/projects/libexif/Dockerfile new file mode 100644 index 000000000..927c71e86 --- /dev/null +++ b/projects/libexif/Dockerfile @@ -0,0 +1,23 @@ +# 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 paul.l.kehrer@gmail.com +RUN apt-get update && apt-get install -y make autoconf automake libtool gettext autopoint +RUN git clone --depth 1 https://github.com/libexif/libexif +RUN git clone --depth 1 https://github.com/ianare/exif-samples +WORKDIR libexif +COPY exif_loader_fuzzer.cc build.sh $SRC/ diff --git a/projects/libexif/build.sh b/projects/libexif/build.sh new file mode 100755 index 000000000..861621056 --- /dev/null +++ b/projects/libexif/build.sh @@ -0,0 +1,29 @@ +#!/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. +# +################################################################################ + +autoreconf -fiv +./configure --disable-docs --enable-shared=no --prefix="$WORK" +make -j$(nproc) +make install + +pushd $SRC +mkdir exif_corpus +find exif-samples -type f -name '*.jpg' -exec mv -n {} exif_corpus/ \; -o -name '*.tiff' -exec mv -n {} exif_corpus/ \; +zip -r "$OUT/exif_loader_fuzzer_seed_corpus.zip" exif_corpus/ +popd + +$CXX $CXXFLAGS -std=c++11 -I"$WORK/include" "$SRC/exif_loader_fuzzer.cc" -o $OUT/exif_loader_fuzzer -lFuzzingEngine "$WORK/lib/libexif.a" diff --git a/projects/libexif/exif_loader_fuzzer.cc b/projects/libexif/exif_loader_fuzzer.cc new file mode 100644 index 000000000..7c32c9c51 --- /dev/null +++ b/projects/libexif/exif_loader_fuzzer.cc @@ -0,0 +1,31 @@ +#include +#include +#include + + +void content_func(ExifEntry *entry, void *user_data) { + char buf[10000]; + exif_entry_get_value(entry, buf, sizeof(buf)); +} + +void data_func(ExifContent *content, void *user_data) { + exif_content_foreach_entry(content, content_func, NULL); +} + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { + ExifLoader *loader = exif_loader_new(); + ExifData *exif_data; + if (!loader) { + return 0; + } + exif_loader_write(loader, const_cast(data), size); + exif_data = exif_loader_get_data(loader); + if(!exif_data) { + exif_loader_unref(loader); + return 0; + } + exif_data_foreach_content(exif_data, data_func, NULL); + exif_loader_unref(loader); + exif_data_unref(exif_data); + return 0; +} diff --git a/projects/libexif/project.yaml b/projects/libexif/project.yaml new file mode 100644 index 000000000..c5ffc9cba --- /dev/null +++ b/projects/libexif/project.yaml @@ -0,0 +1,7 @@ +homepage: "https://libexif.github.io" +primary_contact: "dan@coneharvesters.com" +auto_ccs: + - paul.l.kehrer@gmail.com +sanitizers: + - address + - memory