Skip to content
Myr

Merge branch 'fuzzer_updates' of https://github.com/randy408/stb into working

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Sean Barrett · committed by Sean Barrett · parents f308577, 3b14b5a · Browse files · 6 files+110 added−22 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

6 files+110 added−22 removed

  • tests:+110 added−22 removed

6 files+110 added−22 removed

added:tests/fuzz_main.c+54 added
1#include <stdint.h>2#include <stdio.h>3#include <stdlib.h>45/* fuzz target entry point, works without libFuzzer */67int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size);89int main(int argc, char **argv)10{11 FILE *f;12 char *buf = NULL;13 long siz_buf;1415 if(argc < 2)16 {17 fprintf(stderr, "no input file\n");18 goto err;19 }2021 f = fopen(argv[1], "rb");22 if(f == NULL)23 {24 fprintf(stderr, "error opening input file %s\n", argv[1]);25 goto err;26 }2728 fseek(f, 0, SEEK_END);2930 siz_buf = ftell(f);31 rewind(f);3233 if(siz_buf < 1) goto err;3435 buf = (char*)malloc((size_t)siz_buf);36 if(buf == NULL)37 {38 fprintf(stderr, "malloc() failed\n");39 goto err;40 }4142 if(fread(buf, (size_t)siz_buf, 1, f) != 1)43 {44 fprintf(stderr, "fread() failed\n");45 goto err;46 }4748 (void)LLVMFuzzerTestOneInput((uint8_t*)buf, (size_t)siz_buf);4950err:51 free(buf);5253 return 0;54}
modified:tests/Makefile+3 added-1 removed
1INCLUDES = -I..2CFLAGS = -Wno-pointer-to-int-cast -Wno-int-to-pointer-cast -DSTB_DIVIDE_TEST3CPPFLAGS = -Wno-write-strings -DSTB_DIVIDE_TEST45# Uncomment this line for reproducing OSS-Fuzz bugs with image_fuzzer5#CFLAGS += -O -fsanitize=address6#CFLAGS += -O -fsanitize=address 78all:9 $(CC) $(INCLUDES) $(CFLAGS) ../stb_vorbis.c test_c_compilation.c test_c_lexer.c test_dxt.c test_easyfont.c test_image.c test_image_write.c test_perlin.c test_sprintf.c test_truetype.c test_voxel.c -lm10 $(CC) $(INCLUDES) $(CPPFLAGS) -std=c++0x test_cpp_compilation.cpp -lm -lstdc++11 $(CC) $(INCLUDES) $(CFLAGS) -DIWT_TEST image_write_test.c -lm -o image_write_test12 $(CC) $(INCLUDES) $(CFLAGS) fuzz_main.c stbi_read_fuzzer.c -lm -o image_fuzzer
added:tests/ossfuzz.sh+25 added
deleted:tests/stb_png_read_fuzzer.cpp-19 removed
1#define STB_IMAGE_IMPLEMENTATION2#define STBI_ONLY_PNG3#include "../stb_image.h"45extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)6{7 int x, y, channels;89 if(!stbi_info_from_memory(data, size, &x, &y, &channels)) return 0;1011 /* exit if the image is larger than ~80MB */12 if(y && x > (80000000 / 4) / y) return 0;1314 unsigned char *img = stbi_load_from_memory(data, size, &x, &y, &channels, 4);1516 free(img);1718 return 0;19}
deleted:tests/stb_png_read_fuzzer.options-2 removed
1[libfuzzer]2dict = stb_png.dict
added:tests/stbi_read_fuzzer.c+28 added
1#ifdef __cplusplus2extern "C" {3#endif45#define STB_IMAGE_IMPLEMENTATION67#include "../stb_image.h"8910int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)11{12 int x, y, channels;1314 if(!stbi_info_from_memory(data, size, &x, &y, &channels)) return 0;1516 /* exit if the image is larger than ~80MB */17 if(y && x > (80000000 / 4) / y) return 0;1819 unsigned char *img = stbi_load_from_memory(data, size, &x, &y, &channels, 4);2021 free(img);2223 return 0;24}2526#ifdef __cplusplus27}28#endif