summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xtest/ossfuzz.sh20
-rw-r--r--test/spectre_read_fuzzer.cc46
2 files changed, 66 insertions, 0 deletions
diff --git a/test/ossfuzz.sh b/test/ossfuzz.sh
new file mode 100755
index 0000000..d71fab8
--- /dev/null
+++ b/test/ossfuzz.sh
@@ -0,0 +1,20 @@
+# This script is meant to be run by
+# https://github.com/google/oss-fuzz/blob/master/projects/libspectre/Dockerfile
+
+wget https://github.com/ArtifexSoftware/ghostpdl-downloads/releases/download/gs950/ghostscript-9.50.tar.gz
+tar xvzf ghostscript-9.50.tar.gz
+cd ghostscript-9.50
+./configure
+make -j$(nproc) soinstall
+make -j$(nproc) libgs
+cd ..
+rm /usr/local/lib/libgs.so*
+cp ghostscript-9.50/bin/gs.a /usr/local/lib/libgs.a
+
+./autogen.sh --enable-static --disable-shared
+make -j$(nproc)
+
+$CXX $CXXFLAGS $SRC/libspectre/test/spectre_read_fuzzer.cc -I. \
+ -o $OUT/spectre_read_fuzzer \
+ $LIB_FUZZING_ENGINE $SRC/libspectre/libspectre/.libs/libspectre.a \
+ $SRC/libspectre/ghostscript-9.50/bin/gs.a
diff --git a/test/spectre_read_fuzzer.cc b/test/spectre_read_fuzzer.cc
new file mode 100644
index 0000000..3005bcc
--- /dev/null
+++ b/test/spectre_read_fuzzer.cc
@@ -0,0 +1,46 @@
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <stddef.h>
+#include <inttypes.h>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+#include "../libspectre/spectre.h"
+#include "../libspectre/spectre-utils.h"
+#include "../libspectre/ps.h"
+
+int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
+{
+ SpectreRenderContext *rc;
+ SpectreDocument *document;
+ unsigned int i;
+
+ int fd = open("doc", O_CREAT | O_TMPFILE | O_TRUNC);
+
+ if(fd == -1) return 0;
+
+ while(write(fd, data, size) > 0);
+
+ close(fd);
+
+ spectre_document_load(document, "doc");
+
+ if(spectre_document_status(document))
+ {
+ spectre_document_free(document);
+ return 0;
+ }
+
+ spectre_document_free(document);
+
+ return 0;
+}
+
+#ifdef __cplusplus
+}
+#endif \ No newline at end of file