Home | History | Annotate | Download | only in fuzz
      1 #include <cstdint>
      2 
      3 #include <Magick++/Blob.h>
      4 #include <Magick++/Image.h>
      5 
      6 #include "utils.cc"
      7 
      8 #define FUZZ_ENCODER_STRING_LITERAL_X(name) FUZZ_ENCODER_STRING_LITERAL(name)
      9 #define FUZZ_ENCODER_STRING_LITERAL(name) #name
     10 
     11 #ifndef FUZZ_ENCODER
     12 #define FUZZ_ENCODER FUZZ_ENCODER_STRING_LITERAL_X(FUZZ_IMAGEMAGICK_ENCODER)
     13 #endif
     14 
     15 #ifndef FUZZ_IMAGEMAGICK_INITIALIZER
     16 #define FUZZ_IMAGEMAGICK_INITIALIZER ""
     17 #endif
     18 #define FUZZ_ENCODER_INITIALIZER FUZZ_ENCODER_STRING_LITERAL_X(FUZZ_IMAGEMAGICK_INITIALIZER)
     19 
     20 static ssize_t EncoderInitializer(const uint8_t *Data, const size_t Size, Magick::Image &image)
     21 {
     22   if (FUZZ_ENCODER_INITIALIZER == "interlace") {
     23     Magick::InterlaceType interlace = (Magick::InterlaceType) *reinterpret_cast<const char *>(Data);
     24     if (interlace > Magick::PNGInterlace)
     25       return -1;
     26     image.interlaceType(interlace);
     27     return 1;
     28   }
     29 
     30   return 0;
     31 }
     32 
     33 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
     34   Magick::Image image;
     35   const ssize_t offset = EncoderInitializer(Data, Size, image);
     36   if (offset < 0)
     37     return 0;
     38   std::string encoder = FUZZ_ENCODER;
     39   image.magick(encoder);
     40   image.fileName(std::string(encoder) + ":");
     41   const Magick::Blob blob(Data + offset, Size - offset);
     42   try {
     43     image.ping(blob);
     44   }
     45   catch (Magick::Exception &e) {
     46     return 0;
     47   }
     48   return 0;
     49 }
     50 
     51 #include "travis.cc"
     52