Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions crnlib/Makefile
Original file line number Diff line number Diff line change
@@ -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 = \
Expand Down Expand Up @@ -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)
25 changes: 25 additions & 0 deletions crnlib/crunch_fuzz.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include <cstddef>
#include <cstdint>
#include <string>
#include "crnlib.h"
#include "dds_defs.h"

extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
crn_uint32 crn_size = static_cast<crn_uint32>(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;
}