Project: imagemagick (imagemagick/imagemagick), language: c++
Vulnerability instance: imagemagick.cve-2016-8678
Sanitizer: address

================= Bug Report (1/2) ==================
## Source: Red Hat Bugzilla
## URL: https://bugzilla.redhat.com/show_bug.cgi?id=1385694
## Description:
Bugzilla ID: 1385694
Title: CVE-2016-8678 ImageMagick: Heap-buffer overflow in IsPixelMonochrome

Description
Andrej Nemec 2016-10-17 14:01:34 UTC
A heap-buffer overflow vulnerability was found in ImageMagick in pixel-accessor.h.

References:

http://seclists.org/oss-sec/2016/q4/67
https://blogs.gentoo.org/ago/2016/10/07/imagemagick-heap-based-buffer-overflow-in-ispixelmonochrome-pixel-accessor-h/


Comments:
Comment 1
Andrej Nemec 2016-10-20 08:11:07 UTC
Created ImageMagick tracking bugs for this issue:

Affects: fedora-all [bug 1381145]

---

Comment 2
Adam Mariš 2016-12-09 08:15:46 UTC
Upstream bug:

https://github.com/ImageMagick/ImageMagick/issues/272

Upstream had problems with reproducing the issue. Closed later as Q64 issue, which is not supported.

================= Bug Report (2/2) ==================
## Source: GitHub Issue
## URL: https://github.com/ImageMagick/ImageMagick/issues/272
## Description:
Issue: ImageMagick/ImageMagick#272
Title: heap-based buffer overflow in IsPixelMonochrome (pixel-accessor.h)
State: closed
Created by: asarubbo
Created at: 2016-09-14 13:56:59+00:00

Issue Body:
A crafted image causes an heap overflow.
Reproduce with: identify $FILE
I'm attaching the testcase as a zip because of the github's limitation.
Tested on 7.0.3.0

```
==13198==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x61400000fbc0 at pc 0x7f7a28f71a91 bp 0x7fff6820aaa0 sp 0x7fff6820aa98                                                                                                                                      
READ of size 10 at 0x61400000fbc0 thread T0                                                                                                                                                                                                                                    
    #0 0x7f7a28f71a90 in IsPixelMonochrome /tmp/portage/media-gfx/imagemagick-7.0.3.0/work/ImageMagick-7.0.3-0/./MagickCore/pixel-accessor.h:557:24                                                                                                                            
    #1 0x7f7a28f71a90 in IdentifyImageMonochrome /tmp/portage/media-gfx/imagemagick-7.0.3.0/work/ImageMagick-7.0.3-0/MagickCore/attribute.c:758                                                                                                                                
    #2 0x7f7a28f71dc6 in IdentifyImageType /tmp/portage/media-gfx/imagemagick-7.0.3.0/work/ImageMagick-7.0.3-0/MagickCore/attribute.c:819:7                                                                                                                                    
    #3 0x7f7a293216ce in IdentifyImage /tmp/portage/media-gfx/imagemagick-7.0.3.0/work/ImageMagick-7.0.3-0/MagickCore/identify.c:524:8                                                                                                                                         
    #4 0x7f7a28924f86 in IdentifyImageCommand /tmp/portage/media-gfx/imagemagick-7.0.3.0/work/ImageMagick-7.0.3-0/MagickWand/identify.c:336:22                                                                                                                                 
    #5 0x7f7a289ba26a in MagickCommandGenesis /tmp/portage/media-gfx/imagemagick-7.0.3.0/work/ImageMagick-7.0.3-0/MagickWand/mogrify.c:183:14                                                                                                                                  
    #6 0x4f1fb5 in MagickMain /tmp/portage/media-gfx/imagemagick-7.0.3.0/work/ImageMagick-7.0.3-0/utilities/magick.c:145:10                                                                                                                                                    
    #7 0x4f1fb5 in main /tmp/portage/media-gfx/imagemagick-7.0.3.0/work/ImageMagick-7.0.3-0/utilities/magick.c:176                                                                                                                                                             
    #8 0x7f7a2785e61f in __libc_start_main /var/tmp/portage/sys-libs/glibc-2.22-r4/work/glibc-2.22/csu/libc-start.c:289                                                                                                                                                        
    #9 0x419138 in _init (/usr/bin/magick+0x419138)                                                                                                                                                                                                                            

0x61400000fbc0 is located 0 bytes to the right of 384-byte region [0x61400000fa40,0x61400000fbc0)                                                                                                                                                                              
allocated by thread T0 here:                                                                                                                                                                                                                                                   
    #0 0x4c1105 in __interceptor_posix_memalign /var/tmp/portage/sys-devel/llvm-3.8.1-r2/work/llvm-3.8.1.src/projects/compiler-rt/lib/asan/asan_malloc_linux.cc:124                                                                                                            
    #1 0x7f7a293cac65 in AcquireAlignedMemory /tmp/portage/media-gfx/imagemagick-7.0.3.0/work/ImageMagick-7.0.3-0/MagickCore/memory.c:258:7
    #2 0x7f7a28fb8e9d in AcquireCacheNexusPixels /tmp/portage/media-gfx/imagemagick-7.0.3.0/work/ImageMagick-7.0.3-0/MagickCore/cache.c:4634:33
    #3 0x7f7a28fb8e9d in SetPixelCacheNexusPixels /tmp/portage/media-gfx/imagemagick-7.0.3.0/work/ImageMagick-7.0.3-0/MagickCore/cache.c:4746
    #4 0x7f7a28fa9f9e in GetVirtualPixelsFromNexus /tmp/portage/media-gfx/imagemagick-7.0.3.0/work/ImageMagick-7.0.3-0/MagickCore/cache.c:2629:10
    #5 0x7f7a28fd2a5e in GetCacheViewVirtualPixels /tmp/portage/media-gfx/imagemagick-7.0.3.0/work/ImageMagick-7.0.3-0/MagickCore/cache-view.c:664:10
    #6 0x7f7a28f70e46 in IdentifyImageMonochrome /tmp/portage/media-gfx/imagemagick-7.0.3.0/work/ImageMagick-7.0.3-0/MagickCore/attribute.c:753:7
    #7 0x7f7a28f71dc6 in IdentifyImageType /tmp/portage/media-gfx/imagemagick-7.0.3.0/work/ImageMagick-7.0.3-0/MagickCore/attribute.c:819:7
    #8 0x7f7a293216ce in IdentifyImage /tmp/portage/media-gfx/imagemagick-7.0.3.0/work/ImageMagick-7.0.3-0/MagickCore/identify.c:524:8
    #9 0x7f7a28924f86 in IdentifyImageCommand /tmp/portage/media-gfx/imagemagick-7.0.3.0/work/ImageMagick-7.0.3-0/MagickWand/identify.c:336:22
    #10 0x7f7a289ba26a in MagickCommandGenesis /tmp/portage/media-gfx/imagemagick-7.0.3.0/work/ImageMagick-7.0.3-0/MagickWand/mogrify.c:183:14
    #11 0x4f1fb5 in MagickMain /tmp/portage/media-gfx/imagemagick-7.0.3.0/work/ImageMagick-7.0.3-0/utilities/magick.c:145:10
    #12 0x4f1fb5 in main /tmp/portage/media-gfx/imagemagick-7.0.3.0/work/ImageMagick-7.0.3-0/utilities/magick.c:176
    #13 0x7f7a2785e61f in __libc_start_main /var/tmp/portage/sys-libs/glibc-2.22-r4/work/glibc-2.22/csu/libc-start.c:289

SUMMARY: AddressSanitizer: heap-buffer-overflow /tmp/portage/media-gfx/imagemagick-7.0.3.0/work/ImageMagick-7.0.3-0/./MagickCore/pixel-accessor.h:557:24 in IsPixelMonochrome
Shadow bytes around the buggy address:
  0x0c287fff9f20: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c287fff9f30: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c287fff9f40: fa fa fa fa fa fa fa fa 00 00 00 00 00 00 00 00
  0x0c287fff9f50: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c287fff9f60: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x0c287fff9f70: 00 00 00 00 00 00 00 00[fa]fa fa fa fa fa fa fa
  0x0c287fff9f80: fa fa fa fa fa fa fa fa fd fd fd fd fd fd fd fd
  0x0c287fff9f90: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
  0x0c287fff9fa0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
  0x0c287fff9fb0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fa fa
  0x0c287fff9fc0: fa fa fa fa fa fa fa fa 00 00 00 00 00 00 00 00
Shadow byte legend (one shadow byte represents 8 application bytes):
  Addressable:           00
  Partially addressable: 01 02 03 04 05 06 07 
  Heap left redzone:       fa
  Heap right redzone:      fb
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack partial redzone:   f4
  Stack after return:      f5
  Stack use after scope:   f8
  Global redzone:          f9
  Global init order:       f6
  Poisoned by user:        f7
  Container overflow:      fc
  Array cookie:            ac
  Intra object redzone:    bb
  ASan internal:           fe
  Left alloca redzone:     ca
  Right alloca redzone:    cb
==13198==ABORTING
```

[6.crashes.zip](https://github.com/ImageMagick/ImageMagick/files/472198/6.crashes.zip)



Comments:
Comment by mikayla-grace on 2016-09-14 22:58:13+00:00:
Unfortunately we cannot reproduce this exception with ImageMagick 7.0.3-1.  With ASAN enabled, we get:

```
-> identify 6.crashes
6.crashes TIFF 21x1 21x1+0+0 8-bit Grayscale Gray 319B 0.000u 0:00.000
identify: Invalid TIFF directory; tags are not sorted in ascending order. `TIFFReadDirectoryCheckOrder' @ warning/tiff.c/TIFFWarnings/905.
identify: Unknown field with tag 3 (0x3) encountered. `TIFFReadDirectory' @ warning/tiff.c/TIFFWarnings/905.
identify: Unknown field with tag 512 (0x200) encountered. `TIFFReadDirectory' @ warning/tiff.c/TIFFWarnings/905.
identify: IO error during reading of "Software"; tag ignored. `TIFFFetchNormalTag' @ warning/tiff.c/TIFFWarnings/905.
identify: TIFF directory is missing required "StripByteCounts" field, calculating from imagelength. `TIFFReadDirectory' @ warning/tiff.c/TIFFWarnings/905.
```


---

Comment by asarubbo on 2016-09-15 07:57:15+00:00:
> Unfortunately we cannot reproduce this exception with ImageMagick 7.0.3-1. 

Maybe a different build (compiler,options) is able to hit the crash.
If I can provide more just ask.


---

Comment by mikayla-grace on 2016-09-16 00:10:02+00:00:
Post the output of `identify -list configure`.


---

Comment by asarubbo on 2016-09-16 07:15:51+00:00:
```
Path: /usr/lib64/ImageMagick-7.0.3//config-Q64HDRI/configure.xml                                                                                                                                                                                                               

Name           Value                                                                                                                                                                                                                                                           
-------------------------------------------------------------------------------                                                                                                                                                                                                
CC             afl-clang                                                                                                                                                                                                                                                       
CFLAGS         -I/usr/include/libxml2  -I/usr/include/cairo -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng16  -pthread -I/usr/include/librsvg-2.0 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/cairo -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng16  -I/usr/include/libpng16   -I/usr/include/pango-1.0 -I/usr/include/harfbuzz -I/usr/include/pango-1.0 -I/usr/include/cairo -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng16  -pthread -I/usr/include/OpenEXR   -I/usr/include/lqr-1 -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include  -I/usr/include/openjpeg-2.1   -I/usr/include/graphviz  -I/usr/include/freetype2  -I/usr/include/freetype2  -pthread      -O2 -mtune=generic -march=x86-64 -fno-stack-protector -g3 -ggdb3 -U_FORTIFY_SOURCE -fno-common -fno-omit-frame-pointer -fsanitize=address -Wall -mcpu=no-automagic -fexceptions  -DMAGICKCORE_HDRI_ENABLE=1 -DMAGICKCORE_QUANTUM_DEPTH=64                                                                                                                                                                                                                                               
CODER_PATH     /usr/lib64/ImageMagick-7.0.3/modules-Q64HDRI/coders                                                                                                                                                                                                             
CONFIGURE      ./configure  '--prefix=/usr' '--build=x86_64-pc-linux-gnu' '--host=x86_64-pc-linux-gnu' '--mandir=/usr/share/man' '--infodir=/usr/share/info' '--datadir=/usr/share' '--sysconfdir=/etc' '--localstatedir=/var/lib' '--disable-dependency-tracking' '--disable-silent-rules' '--docdir=/usr/share/doc/imagemagick-7.0.3.0' '--htmldir=/usr/share/doc/imagemagick-7.0.3.0/html' '--libdir=/usr/lib64' '--disable-static' '--enable-hdri' '--disable-opencl' '--with-threads' '--with-modules' '--with-quantum-depth=64' '--with-magick-plus-plus' '--without-perl' '--with-perl-options=INSTALLDIRS=vendor' '--with-gs-font-dir=/usr/share/fonts/urw-fonts' '--with-bzlib' '--without-x' '--with-zlib' '--without-autotrace' '--with-dps' '--with-djvu' '--with-dejavu-font-dir=/usr/share/fonts/dejavu' '--with-fftw' '--without-fpx' '--with-fontconfig' '--with-freetype' '--with-gslib' '--with-gvc' '--with-jbig' '--with-jpeg' '--with-openjp2' '--with-lcms' '--with-lqr' '--with-lzma' '--with-openexr' '--with-pango' '--with-png' '--with-rsvg' '--with-tiff' '--with-webp' '--with-windows-font-dir=/usr/share/fonts/corefonts' '--with-wmf' '--with-xml' '--disable-openmp' '--with-gcc-arch=no-automagic' 'build_alias=x86_64-pc-linux-gnu' 'host_alias=x86_64-pc-linux-gnu' 'CC=afl-clang' 'CFLAGS=-O2 -mtune=generic -march=x86-64 -fno-stack-protector -g3 -ggdb3 -U_FORTIFY_SOURCE -fno-common -fno-omit-frame-pointer -fsanitize=address' 'LDFLAGS=-Wl,-O1 -Wl,--as-needed -Wl,--hash-style=gnu -Wl,-z,lazy -fsanitize=address' 'CXX=afl-clang++' 'CXXFLAGS=-O2 -mtune=generic -march=x86-64 -fno-stack-protector -g3 -ggdb3 -U_FORTIFY_SOURCE -fno-common -fno-omit-frame-pointer -fsanitize=address' 'PKG_CONFIG_PATH=/usr/lib64/pkgconfig'                                                                                                                                                                                            
CONFIGURE_PATH /etc/ImageMagick-7/                                                                                                                                                                                                                                             
COPYRIGHT      Copyright (C) 1999-2016 ImageMagick Studio LLC                                                                                                                                                                                                                  
CPPFLAGS       -I/usr/include/ImageMagick-7                                                                                                                                                                                                                                    
CXX            afl-clang++                                                                                                                                                                                                                                                     
CXXFLAGS       -O2 -mtune=generic -march=x86-64 -fno-stack-protector -g3 -ggdb3 -U_FORTIFY_SOURCE -fno-common -fno-omit-frame-pointer -fsanitize=address                                                                                                                       
DEFS           -DHAVE_CONFIG_H                                                                                                                                                                                                                                                 
DELEGATES      bzlib djvu mpeg fftw fontconfig freetype gslib jbig jng jpeg lcms lqr lzma openexr openjp2 pango png ps rsvg tiff webp wmf xml zlib                                                                                                                             
DISTCHECK_CONFIG_FLAGS 'CC=afl-clang' 'CFLAGS=-O2 -mtune=generic -march=x86-64 -fno-stack-protector -g3 -ggdb3 -U_FORTIFY_SOURCE -fno-common -fno-omit-frame-pointer -fsanitize=address' 'CXX=afl-clang++' 'LDFLAGS=-Wl,-O1 -Wl,--as-needed -Wl,--hash-style=gnu -Wl,-z,lazy -fsanitize=address'  --disable-deprecated  --with-quantum-depth=64  --with-jemalloc=no  --with-umem=no  --with-autotrace=no  --with-dejavu-font-dir=/usr/share/fonts/dejavu  --with-fpx=no  --with-fontpath=  --with-gs-font-dir=/usr/share/fonts/urw-fonts  --with-windows-font-dir=/usr/share/fonts/corefonts  --with-perl=no                                                                                                                                                                                                                                 
DOCUMENTATION_PATH /usr/share/doc/ImageMagick-7                                                                                                                                                                                                                                
EXEC-PREFIX    /usr                                                                                                                                                                                                                                                            
EXECUTABLE_PATH /usr/bin                                                                                                                                                                                                                                                       
FEATURES       DPC HDRI Cipher Modules                                                                                                                                                                                                                                         
FILTER_PATH    /usr/lib64/ImageMagick-7.0.3/modules-Q64HDRI/filters                                                                                                                                                                                                            
GIT_REVISION   11197                                                                                                                                                                                                                                                           
HOST           x86_64-pc-linux-gnu                                                                                                                                                                                                                                             
INCLUDE_PATH   /usr/include/ImageMagick-7                                                                                                                                                                                                                                      
LDFLAGS        -L/usr/lib64 -Wl,-O1 -Wl,--as-needed -Wl,--hash-style=gnu -Wl,-z,lazy -fsanitize=address                                                                                                                                                                        
LIB_VERSION    0x703                                                                                                                                                                                                                                                           
LIB_VERSION_NUMBER 7,0,3,0                                                                                                                                                                                                                                                     
LIBRARY_PATH   /usr/lib64/ImageMagick-7.0.3                                                                                                                                                                                                                                    
LIBS            -llcms2  -lfreetype   -llqr-1 -lglib-2.0  -lfftw3   -lfontconfig -lfreetype      -llzma  -lbz2 -lz  -lltdl  -lm                                                                                                                                                
NAME           ImageMagick                                                                                                                                                                                                                                                     
PCFLAGS        -DMAGICKCORE_HDRI_ENABLE=1 -DMAGICKCORE_QUANTUM_DEPTH=64                                                                                                                                                                                                        
PREFIX         /usr
QuantumDepth   64
RELEASE_DATE   2016-09-14
SHARE_PATH     /usr/share/ImageMagick-7
SHAREARCH_PATH /usr/lib64/ImageMagick-7.0.3/config-Q64HDRI
TARGET_CPU     x86_64
TARGET_OS      linux-gnu
TARGET_VENDOR  pc
VERSION        7.0.3
WEBSITE        http://www.imagemagick.org

Path: [built-in]

Name           Value
-------------------------------------------------------------------------------
FEATURES       
NAME           ImageMagick
QuantumDepth   64
```


---

Comment by marcograss on 2016-09-30 10:04:07+00:00:
to confirm @asarubbo , I also hit this bug with ASAN on master


---

Comment by asarubbo on 2016-09-30 10:06:58+00:00:
Thanks. Do you have found it on your own or based on the flags I posted above?


---

Comment by marcograss on 2016-09-30 10:11:49+00:00:
uhm wait, your test case doesn't crash my instance either.

I have a different test case for a bug in that area of code, so I assumed it was the same bug.

I will open another issue, if they are the same they can merge into this


---

Comment by asarubbo on 2016-09-30 10:20:32+00:00:
with a symbolized output the crash is the same


---

Comment by marcograss on 2016-09-30 10:22:54+00:00:
ok perfect, I guess they can close that new issue


---

Comment by attritionorg on 2016-10-11 04:00:55+00:00:
https://blogs.gentoo.org/ago/2016/10/07/imagemagick-heap-based-buffer-overflow-in-ispixelmonochrome-pixel-accessor-h/

Public post on this issue. Not sure it adds much.


---

Comment by asarubbo on 2016-10-11 13:57:31+00:00:
> https://blogs.gentoo.org/ago/2016/10/07/imagemagick-heap-based-buffer-overflow-in-ispixelmonochrome-pixel-accessor-h/
> 
> Public post on this issue. Not sure it adds much.

It doesn't. Is just my way to track issues I found.

Anyway, this is still reproducible for me with the latest release (7.0.3-4)

```
 AddressSanitizer: heap-buffer-overflow /tmp/portage/media-gfx/imagemagick-7.0.3.4/work/ImageMagick-7.0.3-4/./MagickCore/pixel-accessor.h:557:24 in IsPixelMonochrome
```


---

Comment by mikayla-grace on 2016-10-16 19:33:36+00:00:
Unfortunately we cannot reproduce the problem. We're using afl-clang 3.8.0 and no exception is thrown.


---

Comment by attritionorg on 2016-10-18 16:02:59+00:00:
FYI: Looks like a CVE was assigned to this (2016-8678), even though there are issues in reproducing and confirming.


---

Comment by asarubbo on 2016-10-18 16:05:13+00:00:
the issue was reproduced by @marcograss too.


---

Comment by dlemstra on 2016-11-22 22:56:06+00:00:
This is a Q64 issue and we do not support Q64.  We're waiting for 128bit processors to get Q64 to work.

Attachments:
https://github.com/ImageMagick/ImageMagick/files/472198/6.crashes.zip

Build script:
#!/bin/bash -eu
# Minimized build script with only core build commands
set -eu
./configure --prefix="$WORK" --disable-shared --disable-docs
make "-j$(nproc)"
make install -j$(nproc)

Dockerfile:
FROM hwiwonlee/secb.base:latest
RUN apt-get update && apt-get install -y make autoconf automake libtool
RUN git clone https://github.com/imagemagick/imagemagick imagemagick
RUN git -C imagemagick checkout faccddce0f6cb1e22df9d558b446a17f912e906d
WORKDIR $SRC/imagemagick
COPY build.sh $SRC/

Additional files:
filename: crop_fuzzer.cc
content: #include <cstdint>

#include <Magick++/Blob.h>
#include <Magick++/Image.h>

extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
  uint16_t Width;
  uint16_t Height;
  if (Size < (sizeof(Width) + sizeof(Height))) {
    return 0;
  }
  Width = *reinterpret_cast<const uint16_t *>(Data);
  Height = *reinterpret_cast<const uint16_t *>(Data + sizeof(Width));
  const Magick::Blob blob(Data + sizeof(Width) + sizeof(Height),
                          Size - (sizeof(Width) + sizeof(Height)));
  Magick::Image image;
  try {
    image.read(blob);
  } catch (Magick::Exception &e) {
    return 0;
  }
  image.crop(Magick::Geometry(Width, Height));
  return 0;
}

filename: encoder_fuzzer.cc
content: #include <cstdint>

#include <Magick++/Blob.h>
#include <Magick++/Image.h>

#define FUZZ_ENCODER_STRING_LITERAL(name) #name
#define FUZZ_ENCODER FUZZ_ENCODER_STRING_LITERAL(FUZZ_IMAGEMAGICK_ENCODER)

extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
  const Magick::Blob blob(Data, Size);
  Magick::Image image;
  try {
    image.read(blob);
  } catch (Magick::Exception &e) {
    return 0;
  }

  Magick::Blob outBlob;
  try {
    image.write(&outBlob, FUZZ_ENCODER);
  } catch (Magick::Exception &e) {
  }
  return 0;
}

filename: encoder_list.cc
content: #include <iostream>

#include <Magick++/Blob.h>
#include <Magick++/Image.h>

extern "C" int main() {
  size_t nFormats;
  Magick::ExceptionInfo ex;
  const Magick::MagickInfo **formats = GetMagickInfoList("*", &nFormats, &ex);

  for (size_t i = 0; i < nFormats; i++) {
    const Magick::MagickInfo *format = formats[i];
    if (format->encoder && format->name) {
      std::cout << format->name << std::endl;
    }
  }
}

filename: enhance_fuzzer.cc
content: #include <cstdint>

#include <Magick++/Blob.h>
#include <Magick++/Image.h>

extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
  const Magick::Blob blob(Data, Size);
  Magick::Image image;
  try {
    image.read(blob);
    image.enhance();
  } catch (Magick::Exception &e) {
    return 0;
  }
  return 0;
}

filename: huffman_decode_fuzzer.cc
content: #include <cstdint>

#include <Magick++/Blob.h>
#include <Magick++/Image.h>

extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
  const Magick::Blob blob(Data, Size);
  Magick::Image image;
  try {
    image.read(blob);
  } catch (Magick::Exception &e) {
    return 0;
  }
  Magick::ExceptionInfo ex;
  auto res = HuffmanDecodeImage(image.image(), &ex);
  return 0;
}

filename: rotate_fuzzer.cc
content: #include <cstdint>

#include <Magick++/Blob.h>
#include <Magick++/Image.h>

extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
  if (Size < sizeof(double)) {
    return 0;
  }
  double Degrees = *reinterpret_cast<const double *>(Data);
  if (!isfinite(Degrees)) {
    return 0;
  }
  const Magick::Blob blob(Data + sizeof(Degrees), Size - sizeof(Degrees));
  Magick::Image image;
  try {
    image.read(blob);
  } catch (Magick::Exception &e) {
    return 0;
  }
  image.rotate(Degrees);
  return 0;
}