aboutsummaryrefslogtreecommitdiffhomepage
path: root/projects/libarchive
diff options
context:
space:
mode:
Diffstat (limited to 'projects/libarchive')
-rw-r--r--projects/libarchive/Dockerfile27
-rwxr-xr-xprojects/libarchive/build.sh28
-rw-r--r--projects/libarchive/libarchive_fuzzer.cc54
-rw-r--r--projects/libarchive/target.yaml1
4 files changed, 110 insertions, 0 deletions
diff --git a/projects/libarchive/Dockerfile b/projects/libarchive/Dockerfile
new file mode 100644
index 00000000..d10fa0fd
--- /dev/null
+++ b/projects/libarchive/Dockerfile
@@ -0,0 +1,27 @@
+# Copyright 2016 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 ossfuzz/base-libfuzzer
+MAINTAINER kcwu@google.com
+
+# Installing optional libraries can utilize more code path and/or improve
+# performance (avoid calling external programs).
+RUN apt-get install -y make autoconf automake libtool pkg-config \
+ libbz2-dev liblzo2-dev liblzma-dev liblz4-dev libz-dev \
+ libxml2-dev libssl-dev
+RUN git clone https://github.com/libarchive/libarchive.git
+WORKDIR libarchive
+COPY build.sh libarchive_fuzzer.cc $SRC/
diff --git a/projects/libarchive/build.sh b/projects/libarchive/build.sh
new file mode 100755
index 00000000..275fd68a
--- /dev/null
+++ b/projects/libarchive/build.sh
@@ -0,0 +1,28 @@
+#!/bin/bash -eu
+# Copyright 2016 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.
+#
+################################################################################
+
+# build the target.
+./build/autogen.sh
+./configure
+make -j$(nproc) all
+
+# build your fuzzer(s)
+$CXX $CXXFLAGS -Ilibarchive \
+ $SRC/libarchive_fuzzer.cc -o $OUT/libarchive_fuzzer \
+ -lfuzzer .libs/libarchive.a \
+ -Wl,-Bstatic -lbz2 -llzo2 -lxml2 -llzma -lz -lcrypto -llz4 -licuuc \
+ -licudata -Wl,-Bdynamic
diff --git a/projects/libarchive/libarchive_fuzzer.cc b/projects/libarchive/libarchive_fuzzer.cc
new file mode 100644
index 00000000..fb6fb5a5
--- /dev/null
+++ b/projects/libarchive/libarchive_fuzzer.cc
@@ -0,0 +1,54 @@
+// Copyright 2016 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 <stddef.h>
+#include <stdint.h>
+#include <vector>
+
+#include "archive.h"
+
+struct Buffer {
+ const uint8_t *buf;
+ size_t len;
+};
+
+ssize_t reader_callback(struct archive *a, void *client_data,
+ const void **block) {
+ Buffer *buffer = reinterpret_cast<Buffer *>(client_data);
+ *block = buffer->buf;
+ ssize_t len = buffer->len;
+ buffer->len = 0;
+ return len;
+}
+
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t *buf, size_t len) {
+ struct archive *a = archive_read_new();
+
+ archive_read_support_filter_all(a);
+ archive_read_support_format_all(a);
+
+ Buffer buffer = {buf, len};
+ archive_read_open(a, &buffer, NULL, reader_callback, NULL);
+
+ std::vector<uint8_t> data_buffer(getpagesize(), 0);
+ struct archive_entry *entry;
+ while (archive_read_next_header(a, &entry) == ARCHIVE_OK) {
+ while (archive_read_data(a, data_buffer.data(), data_buffer.size()) > 0)
+ ;
+ }
+
+ archive_read_free(a);
+ return 0;
+}
diff --git a/projects/libarchive/target.yaml b/projects/libarchive/target.yaml
new file mode 100644
index 00000000..7b0161ba
--- /dev/null
+++ b/projects/libarchive/target.yaml
@@ -0,0 +1 @@
+homepage: "https://github.com/libarchive/libarchive"