diff --git a/crnlib/Makefile b/crnlib/Makefile index 9a9de187..02fdac55 100644 --- a/crnlib/Makefile +++ b/crnlib/Makefile @@ -1,4 +1,4 @@ -COMPILE_OPTIONS = -O3 -fomit-frame-pointer -ffast-math -fno-math-errno -g -fno-strict-aliasing -Wall -Wno-unused-value -Wno-unused -march=core2 +COMPILE_OPTIONS = -O3 -fomit-frame-pointer -ffast-math -fno-math-errno -g -fno-strict-aliasing -Wall -Wno-unused-value -Wno-unused -march=core2 ${CXXFLAGS} LINKER_OPTIONS = -lpthread -g OBJECTS = \ @@ -78,19 +78,22 @@ OBJECTS = \ lzma_LzmaLib.o all: crunch +fuzz: crunch_fuzz %.o: %.cpp - g++ $< -o $@ -c $(COMPILE_OPTIONS) + $(CXX) $< -o $@ -c $(COMPILE_OPTIONS) crunch.o: ../crunch/crunch.cpp - g++ $< -o $@ -c -I../inc -I../crnlib $(COMPILE_OPTIONS) + $(CXX) $< -o $@ -c -I../inc -I../crnlib $(COMPILE_OPTIONS) corpus_gen.o: ../crunch/corpus_gen.cpp - g++ $< -o $@ -c -I../inc -I../crnlib $(COMPILE_OPTIONS) + $(CXX) $< -o $@ -c -I../inc -I../crnlib $(COMPILE_OPTIONS) corpus_test.o: ../crunch/corpus_test.cpp - g++ $< -o $@ -c -I../inc -I../crnlib $(COMPILE_OPTIONS) + $(CXX) $< -o $@ -c -I../inc -I../crnlib $(COMPILE_OPTIONS) crunch: $(OBJECTS) crunch.o corpus_gen.o corpus_test.o - g++ $(OBJECTS) crunch.o corpus_gen.o corpus_test.o -o crunch $(LINKER_OPTIONS) + $(CXX) $(OBJECTS) crunch.o corpus_gen.o corpus_test.o -o crunch $(LINKER_OPTIONS) +crunch_fuzz: $(OBJECTS) + $(CXX) ${CXXFLAGS} ${LIB_FUZZING_ENGINE} -I../inc -I../crnlib crunch_fuzz.cpp -o $@ $(OBJECTS) diff --git a/crnlib/crunch_fuzz.cpp b/crnlib/crunch_fuzz.cpp new file mode 100644 index 00000000..7cc8fa0a --- /dev/null +++ b/crnlib/crunch_fuzz.cpp @@ -0,0 +1,25 @@ +#include +#include +#include +#include "crnlib.h" +#include "dds_defs.h" + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { + crn_uint32 crn_size = static_cast(size); + void *dds = crn_decompress_crn_to_dds(data, crn_size); + if (!dds) { + return 0; + } + crn_texture_desc tex_desc; + + // See crnlib.h where cCRNMaxFaces and cCRNMaxLevels are defined for details + // on the library/file limits used within crunch. + crn_uint32 *images[cCRNMaxFaces * cCRNMaxLevels]; + bool success = crn_decompress_dds_to_images(dds, crn_size, images, tex_desc); + crn_free_block(dds); + if (!success) { + return 0; + } + crn_free_all_images(images, tex_desc); + return 0; +}