Skip to content

Commit

Permalink
Merge pull request google#71 from google/oss-fuzz
Browse files Browse the repository at this point in the history
Add fuzzers for consumption by https://github.com/google/oss-fuzz
  • Loading branch information
rsheeter authored Jan 4, 2017
2 parents 63b8fb6 + 8109a2c commit b91b020
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*.o
*.a
/woff2_compress
/woff2_decompress
16 changes: 12 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,21 @@ OS := $(shell uname)

CPPFLAGS = -I./brotli/dec/ -I./brotli/enc/ -I./src

AR ?= ar
CC ?= gcc
CXX ?= g++

COMMON_FLAGS = -fno-omit-frame-pointer -no-canonical-prefixes -DFONT_COMPRESSION_BIN -D __STDC_FORMAT_MACROS
# It's helpful to be able to turn this off for fuzzing
CANONICAL_PREFIXES ?= -no-canonical-prefixes
COMMON_FLAGS = -fno-omit-frame-pointer $(CANONICAL_PREFIXES) -DFONT_COMPRESSION_BIN -D __STDC_FORMAT_MACROS

ifeq ($(OS), Darwin)
CPPFLAGS += -DOS_MACOSX
else
COMMON_FLAGS += -fno-tree-vrp
endif

ARFLAGS = crf
CFLAGS += $(COMMON_FLAGS)
CXXFLAGS += $(COMMON_FLAGS) -std=c++11

Expand All @@ -28,14 +32,18 @@ DECOBJ = $(BROTLI)/dec/*.o

OBJS = $(patsubst %, $(SRCDIR)/%, $(OUROBJ))
EXECUTABLES=woff2_compress woff2_decompress

EXE_OBJS=$(patsubst %, $(SRCDIR)/%.o, $(EXECUTABLES))
ARCHIVES=convert_woff2ttf_fuzzer convert_woff2ttf_fuzzer_new_entry
ARCHIVE_OBJS=$(patsubst %, $(SRCDIR)/%.o, $(ARCHIVES))

ifeq (,$(wildcard $(BROTLI)/*))
$(error Brotli dependency not found : you must initialize the Git submodule)
endif

all : $(OBJS) $(EXECUTABLES)
all : $(OBJS) $(EXECUTABLES) $(ARCHIVES)

$(ARCHIVES) : $(ARCHIVE_OBJS) $(OBJS) deps
$(AR) $(ARFLAGS) $(SRCDIR)/$@.a $(OBJS) $(ENCOBJ) $(DECOBJ) $(SRCDIR)/$@.o

$(EXECUTABLES) : $(EXE_OBJS) deps
$(CXX) $(LFLAGS) $(OBJS) $(ENCOBJ) $(DECOBJ) $(SRCDIR)/$@.o -o $@
Expand All @@ -45,6 +53,6 @@ deps :
$(MAKE) -C $(BROTLI)/enc

clean :
rm -f $(OBJS) $(EXE_OBJS) $(EXECUTABLES)
rm -f $(OBJS) $(EXE_OBJS) $(EXECUTABLES) $(ARCHIVE_OBJS)
$(MAKE) -C $(BROTLI)/dec clean
$(MAKE) -C $(BROTLI)/enc clean
13 changes: 13 additions & 0 deletions src/convert_woff2ttf_fuzzer.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include <stddef.h>
#include <stdint.h>

#include "woff2_dec.h"

// Entry point for LibFuzzer.
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
std::string buf;
woff2::WOFF2StringOut out(&buf);
out.SetMaxSize(30 * 1024 * 1024);
woff2::ConvertWOFF2ToTTF(data, size, &out);
return 0;
}
12 changes: 12 additions & 0 deletions src/convert_woff2ttf_fuzzer_new_entry.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include <string>
#include "woff2_dec.h"

extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t data_size) {
// Decode using newer entry pattern.
// Same pattern as woff2_decompress.
std::string output(std::min(woff2::ComputeWOFF2FinalSize(data, data_size),
woff2::kDefaultMaxSize), 0);
woff2::WOFF2StringOut out(&output);
woff2::ConvertWOFF2ToTTF(data, data_size, &out);
return 0;
}

0 comments on commit b91b020

Please sign in to comment.