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

================= Bug Report (1/1) ==================
## Source: GitHub Issue
## URL: https://github.com/ImageMagick/ImageMagick/issues/587
## Description:
Issue: ImageMagick/ImageMagick#587
Title: Memory-Leak in ReadMATImage() coders/mat.c
State: closed
Created by: lcatro
Created at: 2017-07-18 18:33:59+00:00
Labels: bug

Issue Body:

Crash Link : https://raw.githubusercontent.com/lcatro/My_PoC/master/ImageMagick/memory-leak_ReadMATImage

Trigger Command : ./magick convert memory-leak_ReadMATImage /dev/null

Memory-Leak Detail : 
```
fuzzing@ubuntu:~/fuzzing/ImageMagick/utilities$ ./magick convert image_poc_2017_7_18_8_49_8/input/memory-leak-in-ReadMATImage-953.mat /dev/null 
convert: UnableToOpenConfigureFile `magic.xml' @ warning/configure.c/GetConfigureOptions/715.
convert: ImproperImageHeader `image_poc_2017_7_18_8_49_8/input/memory-leak-in-ReadMATImage-953.mat' @ error/mat.c/ReadMATImage/1354.
convert: NoImagesDefined `/dev/null' @ error/convert.c/ConvertImageCommand/3275.

=================================================================
==43761==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 13488 byte(s) in 1 object(s) allocated from:
    #0 0x7f9dbfd05602 in malloc (/usr/lib/x86_64-linux-gnu/libasan.so.2+0x98602)
    #1 0x7f9dbf202dba in AcquireMagickMemory MagickCore/memory.c:464
    #2 0x7f9dbf1c2e17 in AcquireImage MagickCore/image.c:169
    #3 0x7f9dbf47a5b7 in decompress_block coders/mat.c:570
    #4 0x7f9dbf47c012 in ReadMATImage coders/mat.c:960
    #5 0x7f9dbf0550cd in ReadImage MagickCore/constitute.c:497
    #6 0x7f9dbf0572cc in ReadImages MagickCore/constitute.c:866
    #7 0x7f9dbe81207d in ConvertImageCommand MagickWand/convert.c:641
    #8 0x7f9dbe9a0d68 in MagickCommandGenesis MagickWand/mogrify.c:183
    #9 0x4017f1 in MagickMain utilities/magick.c:149
    #10 0x4019d2 in main utilities/magick.c:180
    #11 0x7f9dbe11582f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)

Indirect leak of 13024 byte(s) in 1 object(s) allocated from:
    #0 0x7f9dbfd05602 in malloc (/usr/lib/x86_64-linux-gnu/libasan.so.2+0x98602)
    #1 0x7f9dbf202dba in AcquireMagickMemory MagickCore/memory.c:464
    #2 0x7f9dbf1c501c in AcquireImageInfo MagickCore/image.c:347
    #3 0x7f9dbf1c809b in CloneImageInfo MagickCore/image.c:952
    #4 0x7f9dbf1d4a9b in SyncImageSettings MagickCore/image.c:4051
    #5 0x7f9dbf1c4bad in AcquireImage MagickCore/image.c:290
    #6 0x7f9dbf47a5b7 in decompress_block coders/mat.c:570
    #7 0x7f9dbf47c012 in ReadMATImage coders/mat.c:960
    #8 0x7f9dbf0550cd in ReadImage MagickCore/constitute.c:497
    #9 0x7f9dbf0572cc in ReadImages MagickCore/constitute.c:866
    #10 0x7f9dbe81207d in ConvertImageCommand MagickWand/convert.c:641
    #11 0x7f9dbe9a0d68 in MagickCommandGenesis MagickWand/mogrify.c:183
    #12 0x4017f1 in MagickMain utilities/magick.c:149
    #13 0x4019d2 in main utilities/magick.c:180
    #14 0x7f9dbe11582f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)

Indirect leak of 9096 byte(s) in 1 object(s) allocated from:
    #0 0x7f9dbfd05602 in malloc (/usr/lib/x86_64-linux-gnu/libasan.so.2+0x98602)
    #1 0x7f9dbf202dba in AcquireMagickMemory MagickCore/memory.c:464
    #2 0x7f9dbf202e0e in AcquireQuantumMemory MagickCore/memory.c:537
    #3 0x7f9dbefe5f2f in AcquirePixelCache MagickCore/cache.c:195
    #4 0x7f9dbf1c354c in AcquireImage MagickCore/image.c:206
    #5 0x7f9dbf47a5b7 in decompress_block coders/mat.c:570
    #6 0x7f9dbf47c012 in ReadMATImage coders/mat.c:960
    #7 0x7f9dbf0550cd in ReadImage MagickCore/constitute.c:497
    #8 0x7f9dbf0572cc in ReadImages MagickCore/constitute.c:866
    #9 0x7f9dbe81207d in ConvertImageCommand MagickWand/convert.c:641
    #10 0x7f9dbe9a0d68 in MagickCommandGenesis MagickWand/mogrify.c:183
    #11 0x4017f1 in MagickMain utilities/magick.c:149
    #12 0x4019d2 in main utilities/magick.c:180
    #13 0x7f9dbe11582f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)

Indirect leak of 528 byte(s) in 1 object(s) allocated from:
    #0 0x7f9dbfd05602 in malloc (/usr/lib/x86_64-linux-gnu/libasan.so.2+0x98602)
    #1 0x7f9dbf202dba in AcquireMagickMemory MagickCore/memory.c:464
    #2 0x7f9dbf202e0e in AcquireQuantumMemory MagickCore/memory.c:537
    #3 0x7f9dbefe6771 in AcquirePixelCacheNexus MagickCore/cache.c:268
    #4 0x7f9dbefe6328 in AcquirePixelCache MagickCore/cache.c:211
    #5 0x7f9dbf1c354c in AcquireImage MagickCore/image.c:206
    #6 0x7f9dbf47a5b7 in decompress_block coders/mat.c:570
    #7 0x7f9dbf47c012 in ReadMATImage coders/mat.c:960
    #8 0x7f9dbf0550cd in ReadImage MagickCore/constitute.c:497
    #9 0x7f9dbf0572cc in ReadImages MagickCore/constitute.c:866
    #10 0x7f9dbe81207d in ConvertImageCommand MagickWand/convert.c:641
    #11 0x7f9dbe9a0d68 in MagickCommandGenesis MagickWand/mogrify.c:183
    #12 0x4017f1 in MagickMain utilities/magick.c:149
    #13 0x4019d2 in main utilities/magick.c:180
    #14 0x7f9dbe11582f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)

Indirect leak of 512 byte(s) in 1 object(s) allocated from:
    #0 0x7f9dbfd05602 in malloc (/usr/lib/x86_64-linux-gnu/libasan.so.2+0x98602)
    #1 0x7f9dbf202dba in AcquireMagickMemory MagickCore/memory.c:464
    #2 0x7f9dbf202e0e in AcquireQuantumMemory MagickCore/memory.c:537
    #3 0x7f9dbf236c86 in AcquirePixelChannelMap MagickCore/pixel.c:101
    #4 0x7f9dbf1c35d5 in AcquireImage MagickCore/image.c:208
    #5 0x7f9dbf47a5b7 in decompress_block coders/mat.c:570
    #6 0x7f9dbf47c012 in ReadMATImage coders/mat.c:960
    #7 0x7f9dbf0550cd in ReadImage MagickCore/constitute.c:497
    #8 0x7f9dbf0572cc in ReadImages MagickCore/constitute.c:866
    #9 0x7f9dbe81207d in ConvertImageCommand MagickWand/convert.c:641
    #10 0x7f9dbe9a0d68 in MagickCommandGenesis MagickWand/mogrify.c:183
    #11 0x4017f1 in MagickMain utilities/magick.c:149
    #12 0x4019d2 in main utilities/magick.c:180
    #13 0x7f9dbe11582f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)

Indirect leak of 280 byte(s) in 1 object(s) allocated from:
    #0 0x7f9dbfd05602 in malloc (/usr/lib/x86_64-linux-gnu/libasan.so.2+0x98602)
    #1 0x7f9dbf202dba in AcquireMagickMemory MagickCore/memory.c:464
    #2 0x7f9dbefcd72b in CloneBlobInfo MagickCore/blob.c:504
    #3 0x7f9dbf1c361a in AcquireImage MagickCore/image.c:209
    #4 0x7f9dbf47a5b7 in decompress_block coders/mat.c:570
    #5 0x7f9dbf47c012 in ReadMATImage coders/mat.c:960
    #6 0x7f9dbf0550cd in ReadImage MagickCore/constitute.c:497
    #7 0x7f9dbf0572cc in ReadImages MagickCore/constitute.c:866
    #8 0x7f9dbe81207d in ConvertImageCommand MagickWand/convert.c:641
    #9 0x7f9dbe9a0d68 in MagickCommandGenesis MagickWand/mogrify.c:183
    #10 0x4017f1 in MagickMain utilities/magick.c:149
    #11 0x4019d2 in main utilities/magick.c:180
    #12 0x7f9dbe11582f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)

Indirect leak of 88 byte(s) in 1 object(s) allocated from:
    #0 0x7f9dbfd05602 in malloc (/usr/lib/x86_64-linux-gnu/libasan.so.2+0x98602)
    #1 0x7f9dbf202dba in AcquireMagickMemory MagickCore/memory.c:464
    #2 0x7f9dbf2fd1d6 in NewSplayTree MagickCore/splay-tree.c:1106
    #3 0x7f9dbf2fa564 in CloneSplayTree MagickCore/splay-tree.c:359
    #4 0x7f9dbf22704d in CloneImageOptions MagickCore/option.c:1880
    #5 0x7f9dbf1c968e in CloneImageInfo MagickCore/image.c:1007
    #6 0x7f9dbf1d4a9b in SyncImageSettings MagickCore/image.c:4051
    #7 0x7f9dbf1c4bad in AcquireImage MagickCore/image.c:290
    #8 0x7f9dbf47a5b7 in decompress_block coders/mat.c:570
    #9 0x7f9dbf47c012 in ReadMATImage coders/mat.c:960
    #10 0x7f9dbf0550cd in ReadImage MagickCore/constitute.c:497
    #11 0x7f9dbf0572cc in ReadImages MagickCore/constitute.c:866
    #12 0x7f9dbe81207d in ConvertImageCommand MagickWand/convert.c:641
    #13 0x7f9dbe9a0d68 in MagickCommandGenesis MagickWand/mogrify.c:183
    #14 0x4017f1 in MagickMain utilities/magick.c:149
    #15 0x4019d2 in main utilities/magick.c:180
    #16 0x7f9dbe11582f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)

Indirect leak of 69 byte(s) in 1 object(s) allocated from:
    #0 0x7f9dbfd05602 in malloc (/usr/lib/x86_64-linux-gnu/libasan.so.2+0x98602)
    #1 0x7f9dbf202dba in AcquireMagickMemory MagickCore/memory.c:464
    #2 0x7f9dbf202e0e in AcquireQuantumMemory MagickCore/memory.c:537
    #3 0x7f9dbf3239ae in ConstantString MagickCore/string.c:701
    #4 0x7f9dbf2fa681 in CloneSplayTree MagickCore/splay-tree.c:372
    #5 0x7f9dbf22704d in CloneImageOptions MagickCore/option.c:1880
    #6 0x7f9dbf1c968e in CloneImageInfo MagickCore/image.c:1007
    #7 0x7f9dbf1d4a9b in SyncImageSettings MagickCore/image.c:4051
    #8 0x7f9dbf1c4bad in AcquireImage MagickCore/image.c:290
    #9 0x7f9dbf47a5b7 in decompress_block coders/mat.c:570
    #10 0x7f9dbf47c012 in ReadMATImage coders/mat.c:960
    #11 0x7f9dbf0550cd in ReadImage MagickCore/constitute.c:497
    #12 0x7f9dbf0572cc in ReadImages MagickCore/constitute.c:866
    #13 0x7f9dbe81207d in ConvertImageCommand MagickWand/convert.c:641
    #14 0x7f9dbe9a0d68 in MagickCommandGenesis MagickWand/mogrify.c:183
    #15 0x4017f1 in MagickMain utilities/magick.c:149
    #16 0x4019d2 in main utilities/magick.c:180
    #17 0x7f9dbe11582f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)

Indirect leak of 64 byte(s) in 1 object(s) allocated from:
    #0 0x7f9dbfd06076 in __interceptor_posix_memalign (/usr/lib/x86_64-linux-gnu/libasan.so.2+0x99076)
    #1 0x7f9dbf2e6fa3 in AcquireSemaphoreMemory MagickCore/semaphore.c:154
    #2 0x7f9dbf2e705f in AcquireSemaphoreInfo MagickCore/semaphore.c:200
    #3 0x7f9dbefd2656 in GetBlobInfo MagickCore/blob.c:1414
    #4 0x7f9dbefcd817 in CloneBlobInfo MagickCore/blob.c:507
    #5 0x7f9dbf1c361a in AcquireImage MagickCore/image.c:209
    #6 0x7f9dbf47a5b7 in decompress_block coders/mat.c:570
    #7 0x7f9dbf47c012 in ReadMATImage coders/mat.c:960
    #8 0x7f9dbf0550cd in ReadImage MagickCore/constitute.c:497
    #9 0x7f9dbf0572cc in ReadImages MagickCore/constitute.c:866
    #10 0x7f9dbe81207d in ConvertImageCommand MagickWand/convert.c:641
    #11 0x7f9dbe9a0d68 in MagickCommandGenesis MagickWand/mogrify.c:183
    #12 0x4017f1 in MagickMain utilities/magick.c:149
    #13 0x4019d2 in main utilities/magick.c:180
    #14 0x7f9dbe11582f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)

Indirect leak of 64 byte(s) in 1 object(s) allocated from:
    #0 0x7f9dbfd06076 in __interceptor_posix_memalign (/usr/lib/x86_64-linux-gnu/libasan.so.2+0x99076)
    #1 0x7f9dbf2e6fa3 in AcquireSemaphoreMemory MagickCore/semaphore.c:154
    #2 0x7f9dbf2e705f in AcquireSemaphoreInfo MagickCore/semaphore.c:200
    #3 0x7f9dbf1c3728 in AcquireImage MagickCore/image.c:213
    #4 0x7f9dbf47a5b7 in decompress_block coders/mat.c:570
    #5 0x7f9dbf47c012 in ReadMATImage coders/mat.c:960
    #6 0x7f9dbf0550cd in ReadImage MagickCore/constitute.c:497
    #7 0x7f9dbf0572cc in ReadImages MagickCore/constitute.c:866
    #8 0x7f9dbe81207d in ConvertImageCommand MagickWand/convert.c:641
    #9 0x7f9dbe9a0d68 in MagickCommandGenesis MagickWand/mogrify.c:183
    #10 0x4017f1 in MagickMain utilities/magick.c:149
    #11 0x4019d2 in main utilities/magick.c:180
    #12 0x7f9dbe11582f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)

Indirect leak of 64 byte(s) in 1 object(s) allocated from:
    #0 0x7f9dbfd06076 in __interceptor_posix_memalign (/usr/lib/x86_64-linux-gnu/libasan.so.2+0x99076)
    #1 0x7f9dbf202d17 in AcquireAlignedMemory MagickCore/memory.c:262
    #2 0x7f9dbefe6680 in AcquirePixelCacheNexus MagickCore/cache.c:264
    #3 0x7f9dbefe6328 in AcquirePixelCache MagickCore/cache.c:211
    #4 0x7f9dbf1c354c in AcquireImage MagickCore/image.c:206
    #5 0x7f9dbf47a5b7 in decompress_block coders/mat.c:570
    #6 0x7f9dbf47c012 in ReadMATImage coders/mat.c:960
    #7 0x7f9dbf0550cd in ReadImage MagickCore/constitute.c:497
    #8 0x7f9dbf0572cc in ReadImages MagickCore/constitute.c:866
    #9 0x7f9dbe81207d in ConvertImageCommand MagickWand/convert.c:641
    #10 0x7f9dbe9a0d68 in MagickCommandGenesis MagickWand/mogrify.c:183
    #11 0x4017f1 in MagickMain utilities/magick.c:149
    #12 0x4019d2 in main utilities/magick.c:180
    #13 0x7f9dbe11582f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)

Indirect leak of 64 byte(s) in 1 object(s) allocated from:
    #0 0x7f9dbfd06076 in __interceptor_posix_memalign (/usr/lib/x86_64-linux-gnu/libasan.so.2+0x99076)
    #1 0x7f9dbf2e6fa3 in AcquireSemaphoreMemory MagickCore/semaphore.c:154
    #2 0x7f9dbf2e705f in AcquireSemaphoreInfo MagickCore/semaphore.c:200
    #3 0x7f9dbf2fd4a3 in NewSplayTree MagickCore/splay-tree.c:1119
    #4 0x7f9dbf2fa564 in CloneSplayTree MagickCore/splay-tree.c:359
    #5 0x7f9dbf22704d in CloneImageOptions MagickCore/option.c:1880
    #6 0x7f9dbf1c968e in CloneImageInfo MagickCore/image.c:1007
    #7 0x7f9dbf1d4a9b in SyncImageSettings MagickCore/image.c:4051
    #8 0x7f9dbf1c4bad in AcquireImage MagickCore/image.c:290
    #9 0x7f9dbf47a5b7 in decompress_block coders/mat.c:570
    #10 0x7f9dbf47c012 in ReadMATImage coders/mat.c:960
    #11 0x7f9dbf0550cd in ReadImage MagickCore/constitute.c:497
    #12 0x7f9dbf0572cc in ReadImages MagickCore/constitute.c:866
    #13 0x7f9dbe81207d in ConvertImageCommand MagickWand/convert.c:641
    #14 0x7f9dbe9a0d68 in MagickCommandGenesis MagickWand/mogrify.c:183
    #15 0x4017f1 in MagickMain utilities/magick.c:149
    #16 0x4019d2 in main utilities/magick.c:180
    #17 0x7f9dbe11582f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)

Indirect leak of 64 byte(s) in 1 object(s) allocated from:
    #0 0x7f9dbfd06076 in __interceptor_posix_memalign (/usr/lib/x86_64-linux-gnu/libasan.so.2+0x99076)
    #1 0x7f9dbf2e6fa3 in AcquireSemaphoreMemory MagickCore/semaphore.c:154
    #2 0x7f9dbf2e705f in AcquireSemaphoreInfo MagickCore/semaphore.c:200
    #3 0x7f9dbefe6531 in AcquirePixelCache MagickCore/cache.c:226
    #4 0x7f9dbf1c354c in AcquireImage MagickCore/image.c:206
    #5 0x7f9dbf47a5b7 in decompress_block coders/mat.c:570
    #6 0x7f9dbf47c012 in ReadMATImage coders/mat.c:960
    #7 0x7f9dbf0550cd in ReadImage MagickCore/constitute.c:497
    #8 0x7f9dbf0572cc in ReadImages MagickCore/constitute.c:866
    #9 0x7f9dbe81207d in ConvertImageCommand MagickWand/convert.c:641
    #10 0x7f9dbe9a0d68 in MagickCommandGenesis MagickWand/mogrify.c:183
    #11 0x4017f1 in MagickMain utilities/magick.c:149
    #12 0x4019d2 in main utilities/magick.c:180
    #13 0x7f9dbe11582f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)

Indirect leak of 64 byte(s) in 1 object(s) allocated from:
    #0 0x7f9dbfd06076 in __interceptor_posix_memalign (/usr/lib/x86_64-linux-gnu/libasan.so.2+0x99076)
    #1 0x7f9dbf2e6fa3 in AcquireSemaphoreMemory MagickCore/semaphore.c:154
    #2 0x7f9dbf2e705f in AcquireSemaphoreInfo MagickCore/semaphore.c:200
    #3 0x7f9dbefe65a1 in AcquirePixelCache MagickCore/cache.c:228
    #4 0x7f9dbf1c354c in AcquireImage MagickCore/image.c:206
    #5 0x7f9dbf47a5b7 in decompress_block coders/mat.c:570
    #6 0x7f9dbf47c012 in ReadMATImage coders/mat.c:960
    #7 0x7f9dbf0550cd in ReadImage MagickCore/constitute.c:497
    #8 0x7f9dbf0572cc in ReadImages MagickCore/constitute.c:866
    #9 0x7f9dbe81207d in ConvertImageCommand MagickWand/convert.c:641
    #10 0x7f9dbe9a0d68 in MagickCommandGenesis MagickWand/mogrify.c:183
    #11 0x4017f1 in MagickMain utilities/magick.c:149
    #12 0x4019d2 in main utilities/magick.c:180
    #13 0x7f9dbe11582f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)

Indirect leak of 32 byte(s) in 1 object(s) allocated from:
    #0 0x7f9dbfd05602 in malloc (/usr/lib/x86_64-linux-gnu/libasan.so.2+0x98602)
    #1 0x7f9dbf202dba in AcquireMagickMemory MagickCore/memory.c:464
    #2 0x7f9dbf2f99ea in AddValueToSplayTree MagickCore/splay-tree.c:188
    #3 0x7f9dbf2fa6ed in CloneSplayTree MagickCore/splay-tree.c:371
    #4 0x7f9dbf22704d in CloneImageOptions MagickCore/option.c:1880
    #5 0x7f9dbf1c968e in CloneImageInfo MagickCore/image.c:1007
    #6 0x7f9dbf1d4a9b in SyncImageSettings MagickCore/image.c:4051
    #7 0x7f9dbf1c4bad in AcquireImage MagickCore/image.c:290
    #8 0x7f9dbf47a5b7 in decompress_block coders/mat.c:570
    #9 0x7f9dbf47c012 in ReadMATImage coders/mat.c:960
    #10 0x7f9dbf0550cd in ReadImage MagickCore/constitute.c:497
    #11 0x7f9dbf0572cc in ReadImages MagickCore/constitute.c:866
    #12 0x7f9dbe81207d in ConvertImageCommand MagickWand/convert.c:641
    #13 0x7f9dbe9a0d68 in MagickCommandGenesis MagickWand/mogrify.c:183
    #14 0x4017f1 in MagickMain utilities/magick.c:149
    #15 0x4019d2 in main utilities/magick.c:180
    #16 0x7f9dbe11582f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)

Indirect leak of 9 byte(s) in 1 object(s) allocated from:
    #0 0x7f9dbfd05602 in malloc (/usr/lib/x86_64-linux-gnu/libasan.so.2+0x98602)
    #1 0x7f9dbf202dba in AcquireMagickMemory MagickCore/memory.c:464
    #2 0x7f9dbf202e0e in AcquireQuantumMemory MagickCore/memory.c:537
    #3 0x7f9dbf3239ae in ConstantString MagickCore/string.c:701
    #4 0x7f9dbf2fa6d8 in CloneSplayTree MagickCore/splay-tree.c:371
    #5 0x7f9dbf22704d in CloneImageOptions MagickCore/option.c:1880
    #6 0x7f9dbf1c968e in CloneImageInfo MagickCore/image.c:1007
    #7 0x7f9dbf1d4a9b in SyncImageSettings MagickCore/image.c:4051
    #8 0x7f9dbf1c4bad in AcquireImage MagickCore/image.c:290
    #9 0x7f9dbf47a5b7 in decompress_block coders/mat.c:570
    #10 0x7f9dbf47c012 in ReadMATImage coders/mat.c:960
    #11 0x7f9dbf0550cd in ReadImage MagickCore/constitute.c:497
    #12 0x7f9dbf0572cc in ReadImages MagickCore/constitute.c:866
    #13 0x7f9dbe81207d in ConvertImageCommand MagickWand/convert.c:641
    #14 0x7f9dbe9a0d68 in MagickCommandGenesis MagickWand/mogrify.c:183
    #15 0x4017f1 in MagickMain utilities/magick.c:149
    #16 0x4019d2 in main utilities/magick.c:180
    #17 0x7f9dbe11582f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)

SUMMARY: AddressSanitizer: 37510 byte(s) leaked in 16 allocation(s).
```


Comments:
Comment by mikayla-grace on 2017-07-18 22:29:27+00:00:
Thanks for the problem report.  We can reproduce it and will have a patch to fix it in GIT master branch @ https://github.com/ImageMagick/ImageMagick later today.  The patch will be available in the beta releases of ImageMagick @ http://www.imagemagick.org/download/beta/ by sometime tomorrow. 


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 9871b4ad7400606bbecf7f979b198080f4b107c3
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;
}