stbi_read_fuzzer.c 502 B

12345678910111213141516171819202122232425262728
  1. #ifdef __cplusplus
  2. extern "C" {
  3. #endif
  4. #define STB_IMAGE_IMPLEMENTATION
  5. #include "../stb_image.h"
  6. int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
  7. {
  8. int x, y, channels;
  9. if(!stbi_info_from_memory(data, size, &x, &y, &channels)) return 0;
  10. /* exit if the image is larger than ~80MB */
  11. if(y && x > (80000000 / 4) / y) return 0;
  12. unsigned char *img = stbi_load_from_memory(data, size, &x, &y, &channels, 4);
  13. free(img);
  14. return 0;
  15. }
  16. #ifdef __cplusplus
  17. }
  18. #endif