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

================= Bug Report (1/1) ==================
## Source: GitHub Issue
## URL: https://github.com/ImageMagick/ImageMagick/issues/1616
## Description:
Issue: ImageMagick/ImageMagick#1616
Title: memory leaks is detected at AcquireMagickMemory
State: closed
Created by: SuhwanSong
Created at: 2019-06-23 08:45:54+00:00
Labels: bug

Issue Body:
### Prerequisites

- [x] I have written a descriptive issue title
- [x] I have verified that I am using the latest version of ImageMagick
- [x] I have searched [open](https://github.com/ImageMagick/ImageMagick/issues) and [closed](https://github.com/ImageMagick/ImageMagick/issues?q=is%3Aissue+is%3Aclosed) issues to ensure it has not already been reported

### Description
<!-- A description of the bug or feature -->
There's memory leaks in MagickCore/memory.c:478:10
This issue is maybe related with [#1604](https://github.com/ImageMagick/ImageMagick/issues/1604).

### Steps to Reproduce
<!-- List of steps, sample code, failing test or link to a project that reproduces the behavior.
     Make sure you place a stack trace inside a code (```) block to avoid linking unrelated issues -->
run_cmd:
`magick -seed 0 -quality 3 "(" magick:logo +repage ")" "(" magick:wizard +repage ")" -quiet -caption "%h%U" -compare -insert 2   tmp`

Here's ASAN log.
```
==22113==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 13504 byte(s) in 1 object(s) allocated from:
    #0 0x4e5397 in __interceptor_malloc (install/bin/magick+0x4e5397)
    #1 0x7f9c4c438106 in AcquireMagickMemory MagickCore/memory.c:478:10
    #2 0x7f9c4c3e5114 in AcquireCriticalMemory ./MagickCore/memory-private.h:64:10
    #3 0x7f9c4c3e96c9 in CloneImage MagickCore/image.c:823:25
    #4 0x7f9c4c5e8885 in ExtentImage MagickCore/transform.c:1134:16
    #5 0x7f9c4c1c5d00 in CompareImages MagickCore/compare.c:188:20
    #6 0x7f9c4bbb06f1 in CLIListOperatorImages MagickWand/operation.c:3880:22
    #7 0x7f9c4bbbc35e in CLIOption MagickWand/operation.c:5279:14
    #8 0x7f9c4b9fda99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
    #9 0x7f9c4b9fed0a in MagickImageCommand MagickWand/magick-cli.c:796:5
    #10 0x7f9c4ba48ba1 in MagickCommandGenesis MagickWand/mogrify.c:185:14
    #11 0x526f95 in MagickMain utilities/magick.c:149:10
    #12 0x5268e1 in main utilities/magick.c:180:10
    #13 0x7f9c464bfb96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)

Indirect leak of 6553600 byte(s) in 1 object(s) allocated from:
    #0 0x4e6200 in __interceptor_posix_memalign (install/bin/magick+0x4e6200)
    #1 0x7f9c4c437f26 in AcquireAlignedMemory MagickCore/memory.c:265:7
    #2 0x7f9c4c18061c in OpenPixelCache MagickCore/cache.c:3728:46
    #3 0x7f9c4c186901 in GetImagePixelCache MagickCore/cache.c:1754:18
    #4 0x7f9c4c16e330 in QueueAuthenticPixelCacheNexus MagickCore/cache.c:4156:28
    #5 0x7f9c4c16e001 in GetAuthenticPixelCacheNexus MagickCore/cache.c:1324:10
    #6 0x7f9c4c1909be in GetCacheViewAuthenticPixels MagickCore/cache-view.c:312:10
    #7 0x7f9c4c3f83a1 in SetImageAlpha MagickCore/image.c:2372:7
    #8 0x7f9c4c479695 in ConformPixelInfo MagickCore/pixel.c:235:12
    #9 0x7f9c4c3ec4a7 in SetImageBackgroundColor MagickCore/image.c:2441:3
    #10 0x7f9c4c5e88b5 in ExtentImage MagickCore/transform.c:1138:10
    #11 0x7f9c4c1c5d00 in CompareImages MagickCore/compare.c:188:20
    #12 0x7f9c4bbb06f1 in CLIListOperatorImages MagickWand/operation.c:3880:22
    #13 0x7f9c4bbbc35e in CLIOption MagickWand/operation.c:5279:14
    #14 0x7f9c4b9fda99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
    #15 0x7f9c4b9fed0a in MagickImageCommand MagickWand/magick-cli.c:796:5
    #16 0x7f9c4ba48ba1 in MagickCommandGenesis MagickWand/mogrify.c:185:14
    #17 0x526f95 in MagickMain utilities/magick.c:149:10
    #18 0x5268e1 in main utilities/magick.c:180:10
    #19 0x7f9c464bfb96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)

Indirect leak of 22616 byte(s) in 1 object(s) allocated from:
    #0 0x4e5397 in __interceptor_malloc (install/bin/magick+0x4e5397)
    #1 0x7f9c4c438106 in AcquireMagickMemory MagickCore/memory.c:478:10
    #2 0x7f9c4c43816f in AcquireQuantumMemory MagickCore/memory.c:551:10
    #3 0x7f9c4c3eaafd in CloneImage MagickCore/image.c:879:43
    #4 0x7f9c4c5e8885 in ExtentImage MagickCore/transform.c:1134:16
    #5 0x7f9c4c1c5d00 in CompareImages MagickCore/compare.c:188:20
    #6 0x7f9c4bbb06f1 in CLIListOperatorImages MagickWand/operation.c:3880:22
    #7 0x7f9c4bbbc35e in CLIOption MagickWand/operation.c:5279:14
    #8 0x7f9c4b9fda99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
    #9 0x7f9c4b9fed0a in MagickImageCommand MagickWand/magick-cli.c:796:5
    #10 0x7f9c4ba48ba1 in MagickCommandGenesis MagickWand/mogrify.c:185:14
    #11 0x526f95 in MagickMain utilities/magick.c:149:10
    #12 0x5268e1 in main utilities/magick.c:180:10
    #13 0x7f9c464bfb96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)

Indirect leak of 13024 byte(s) in 1 object(s) allocated from:
    #0 0x4e5397 in __interceptor_malloc (install/bin/magick+0x4e5397)
    #1 0x7f9c4c438106 in AcquireMagickMemory MagickCore/memory.c:478:10
    #2 0x7f9c4c3e5114 in AcquireCriticalMemory ./MagickCore/memory-private.h:64:10
    #3 0x7f9c4c3e7753 in AcquireImageInfo MagickCore/image.c:350:28
    #4 0x7f9c4c3f0513 in CloneImageInfo MagickCore/image.c:945:14
    #5 0x7f9c4c3e7678 in SyncImageSettings MagickCore/image.c:4242:21
    #6 0x7f9c4c3fee66 in SyncImagesSettings MagickCore/image.c:4000:12
    #7 0x7f9c4bbbc163 in CLIOption MagickWand/operation.c:5246:14
    #8 0x7f9c4b9fda99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
    #9 0x7f9c4b9fed0a in MagickImageCommand MagickWand/magick-cli.c:796:5
    #10 0x7f9c4ba48ba1 in MagickCommandGenesis MagickWand/mogrify.c:185:14
    #11 0x526f95 in MagickMain utilities/magick.c:149:10
    #12 0x5268e1 in main utilities/magick.c:180:10
    #13 0x7f9c464bfb96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)

Indirect leak of 9152 byte(s) in 1 object(s) allocated from:
    #0 0x4e6200 in __interceptor_posix_memalign (install/bin/magick+0x4e6200)
    #1 0x7f9c4c437f26 in AcquireAlignedMemory MagickCore/memory.c:265:7
    #2 0x7f9c4c16aa04 in AcquirePixelCache MagickCore/cache.c:195:28
    #3 0x7f9c4c16bf8d in ClonePixelCache MagickCore/cache.c:513:28
    #4 0x7f9c4c3eb59f in CloneImage MagickCore/image.c:910:22
    #5 0x7f9c4c5e8885 in ExtentImage MagickCore/transform.c:1134:16
    #6 0x7f9c4c1c5d00 in CompareImages MagickCore/compare.c:188:20
    #7 0x7f9c4bbb06f1 in CLIListOperatorImages MagickWand/operation.c:3880:22
    #8 0x7f9c4bbbc35e in CLIOption MagickWand/operation.c:5279:14
    #9 0x7f9c4b9fda99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
    #10 0x7f9c4b9fed0a in MagickImageCommand MagickWand/magick-cli.c:796:5
    #11 0x7f9c4ba48ba1 in MagickCommandGenesis MagickWand/mogrify.c:185:14
    #12 0x526f95 in MagickMain utilities/magick.c:149:10
    #13 0x5268e1 in main utilities/magick.c:180:10
    #14 0x7f9c464bfb96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)

Indirect leak of 512 byte(s) in 1 object(s) allocated from:
    #0 0x4e5397 in __interceptor_malloc (install/bin/magick+0x4e5397)
    #1 0x7f9c4c438106 in AcquireMagickMemory MagickCore/memory.c:478:10
    #2 0x7f9c4c43816f in AcquireQuantumMemory MagickCore/memory.c:551:10
    #3 0x7f9c4c478f3a in AcquirePixelChannelMap MagickCore/pixel.c:101:35
    #4 0x7f9c4c479114 in ClonePixelChannelMap MagickCore/pixel.c:139:13
    #5 0x7f9c4c3ea34f in CloneImage MagickCore/image.c:849:28
    #6 0x7f9c4c5e8885 in ExtentImage MagickCore/transform.c:1134:16
    #7 0x7f9c4c1c5d00 in CompareImages MagickCore/compare.c:188:20
    #8 0x7f9c4bbb06f1 in CLIListOperatorImages MagickWand/operation.c:3880:22
    #9 0x7f9c4bbbc35e in CLIOption MagickWand/operation.c:5279:14
    #10 0x7f9c4b9fda99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
    #11 0x7f9c4b9fed0a in MagickImageCommand MagickWand/magick-cli.c:796:5
    #12 0x7f9c4ba48ba1 in MagickCommandGenesis MagickWand/mogrify.c:185:14
    #13 0x526f95 in MagickMain utilities/magick.c:149:10
    #14 0x5268e1 in main utilities/magick.c:180:10
    #15 0x7f9c464bfb96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)

Indirect leak of 288 byte(s) in 1 object(s) allocated from:
    #0 0x4e5397 in __interceptor_malloc (install/bin/magick+0x4e5397)
    #1 0x7f9c4c438106 in AcquireMagickMemory MagickCore/memory.c:478:10
    #2 0x7f9c4c148284 in AcquireCriticalMemory ./MagickCore/memory-private.h:64:10
    #3 0x7f9c4c149d5d in CloneBlobInfo MagickCore/blob.c:554:27
    #4 0x7f9c4c3ea808 in CloneImage MagickCore/image.c:867:25
    #5 0x7f9c4c5e8885 in ExtentImage MagickCore/transform.c:1134:16
    #6 0x7f9c4c1c5d00 in CompareImages MagickCore/compare.c:188:20
    #7 0x7f9c4bbb06f1 in CLIListOperatorImages MagickWand/operation.c:3880:22
    #8 0x7f9c4bbbc35e in CLIOption MagickWand/operation.c:5279:14
    #9 0x7f9c4b9fda99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
    #10 0x7f9c4b9fed0a in MagickImageCommand MagickWand/magick-cli.c:796:5
    #11 0x7f9c4ba48ba1 in MagickCommandGenesis MagickWand/mogrify.c:185:14
    #12 0x526f95 in MagickMain utilities/magick.c:149:10
    #13 0x5268e1 in main utilities/magick.c:180:10
    #14 0x7f9c464bfb96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)

Indirect leak of 192 byte(s) in 1 object(s) allocated from:
    #0 0x4e5397 in __interceptor_malloc (install/bin/magick+0x4e5397)
    #1 0x7f9c4c438106 in AcquireMagickMemory MagickCore/memory.c:478:10
    #2 0x7f9c4c43816f in AcquireQuantumMemory MagickCore/memory.c:551:10
    #3 0x7f9c4c16b5df in AcquirePixelCacheNexus MagickCore/cache.c:271:29
    #4 0x7f9c4c16af8d in AcquirePixelCache MagickCore/cache.c:212:26
    #5 0x7f9c4c16bf8d in ClonePixelCache MagickCore/cache.c:513:28
    #6 0x7f9c4c3eb59f in CloneImage MagickCore/image.c:910:22
    #7 0x7f9c4c5e8885 in ExtentImage MagickCore/transform.c:1134:16
    #8 0x7f9c4c1c5d00 in CompareImages MagickCore/compare.c:188:20
    #9 0x7f9c4bbb06f1 in CLIListOperatorImages MagickWand/operation.c:3880:22
    #10 0x7f9c4bbbc35e in CLIOption MagickWand/operation.c:5279:14
    #11 0x7f9c4b9fda99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
    #12 0x7f9c4b9fed0a in MagickImageCommand MagickWand/magick-cli.c:796:5
    #13 0x7f9c4ba48ba1 in MagickCommandGenesis MagickWand/mogrify.c:185:14
    #14 0x526f95 in MagickMain utilities/magick.c:149:10
    #15 0x5268e1 in main utilities/magick.c:180:10
    #16 0x7f9c464bfb96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)

Indirect leak of 96 byte(s) in 3 object(s) allocated from:
    #0 0x4e5397 in __interceptor_malloc (install/bin/magick+0x4e5397)
    #1 0x7f9c4c438106 in AcquireMagickMemory MagickCore/memory.c:478:10
    #2 0x7f9c4c593033 in AddValueToSplayTree MagickCore/splay-tree.c:189:21
    #3 0x7f9c4c593f3c in CloneSplayTree MagickCore/splay-tree.c:372:12
    #4 0x7f9c4c4c8ee3 in CloneImageProperties MagickCore/property.c:196:25
    #5 0x7f9c4c3e9f59 in CloneImage MagickCore/image.c:839:10
    #6 0x7f9c4c5e8885 in ExtentImage MagickCore/transform.c:1134:16
    #7 0x7f9c4c1c5d00 in CompareImages MagickCore/compare.c:188:20
    #8 0x7f9c4bbb06f1 in CLIListOperatorImages MagickWand/operation.c:3880:22
    #9 0x7f9c4bbbc35e in CLIOption MagickWand/operation.c:5279:14
    #10 0x7f9c4b9fda99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
    #11 0x7f9c4b9fed0a in MagickImageCommand MagickWand/magick-cli.c:796:5
    #12 0x7f9c4ba48ba1 in MagickCommandGenesis MagickWand/mogrify.c:185:14
    #13 0x526f95 in MagickMain utilities/magick.c:149:10
    #14 0x5268e1 in main utilities/magick.c:180:10
    #15 0x7f9c464bfb96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)

Indirect leak of 88 byte(s) in 1 object(s) allocated from:
    #0 0x4e5397 in __interceptor_malloc (install/bin/magick+0x4e5397)
    #1 0x7f9c4c438106 in AcquireMagickMemory MagickCore/memory.c:478:10
    #2 0x7f9c4c598084 in AcquireCriticalMemory ./MagickCore/memory-private.h:64:10
    #3 0x7f9c4c594115 in NewSplayTree MagickCore/splay-tree.c:1148:32
    #4 0x7f9c4c593d24 in CloneSplayTree MagickCore/splay-tree.c:360:14
    #5 0x7f9c4c4c8ee3 in CloneImageProperties MagickCore/property.c:196:25
    #6 0x7f9c4c3e9f59 in CloneImage MagickCore/image.c:839:10
    #7 0x7f9c4c5e8885 in ExtentImage MagickCore/transform.c:1134:16
    #8 0x7f9c4c1c5d00 in CompareImages MagickCore/compare.c:188:20
    #9 0x7f9c4bbb06f1 in CLIListOperatorImages MagickWand/operation.c:3880:22
    #10 0x7f9c4bbbc35e in CLIOption MagickWand/operation.c:5279:14
    #11 0x7f9c4b9fda99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
    #12 0x7f9c4b9fed0a in MagickImageCommand MagickWand/magick-cli.c:796:5
    #13 0x7f9c4ba48ba1 in MagickCommandGenesis MagickWand/mogrify.c:185:14
    #14 0x526f95 in MagickMain utilities/magick.c:149:10
    #15 0x5268e1 in main utilities/magick.c:180:10
    #16 0x7f9c464bfb96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)

Indirect leak of 88 byte(s) in 1 object(s) allocated from:
    #0 0x4e5397 in __interceptor_malloc (install/bin/magick+0x4e5397)
    #1 0x7f9c4c438106 in AcquireMagickMemory MagickCore/memory.c:478:10
    #2 0x7f9c4c598084 in AcquireCriticalMemory ./MagickCore/memory-private.h:64:10
    #3 0x7f9c4c594115 in NewSplayTree MagickCore/splay-tree.c:1148:32
    #4 0x7f9c4c593d24 in CloneSplayTree MagickCore/splay-tree.c:360:14
    #5 0x7f9c4c4698c0 in CloneImageOptions MagickCore/option.c:2144:27
    #6 0x7f9c4c3f2018 in CloneImageInfo MagickCore/image.c:1010:10
    #7 0x7f9c4c3e7678 in SyncImageSettings MagickCore/image.c:4242:21
    #8 0x7f9c4c3fee66 in SyncImagesSettings MagickCore/image.c:4000:12
    #9 0x7f9c4bbbc163 in CLIOption MagickWand/operation.c:5246:14
    #10 0x7f9c4b9fda99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
    #11 0x7f9c4b9fed0a in MagickImageCommand MagickWand/magick-cli.c:796:5
    #12 0x7f9c4ba48ba1 in MagickCommandGenesis MagickWand/mogrify.c:185:14
    #13 0x526f95 in MagickMain utilities/magick.c:149:10
    #14 0x5268e1 in main utilities/magick.c:180:10
    #15 0x7f9c464bfb96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)

Indirect leak of 64 byte(s) in 1 object(s) allocated from:
    #0 0x4e6200 in __interceptor_posix_memalign (install/bin/magick+0x4e6200)
    #1 0x7f9c4c57d781 in AcquireSemaphoreMemory MagickCore/semaphore.c:154:7
    #2 0x7f9c4c57cfc3 in AcquireSemaphoreInfo MagickCore/semaphore.c:200:36
    #3 0x7f9c4c16b383 in AcquirePixelCache MagickCore/cache.c:231:30
    #4 0x7f9c4c16bf8d in ClonePixelCache MagickCore/cache.c:513:28
    #5 0x7f9c4c3eb59f in CloneImage MagickCore/image.c:910:22
    #6 0x7f9c4c5e8885 in ExtentImage MagickCore/transform.c:1134:16
    #7 0x7f9c4c1c5d00 in CompareImages MagickCore/compare.c:188:20
    #8 0x7f9c4bbb06f1 in CLIListOperatorImages MagickWand/operation.c:3880:22
    #9 0x7f9c4bbbc35e in CLIOption MagickWand/operation.c:5279:14
    #10 0x7f9c4b9fda99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
    #11 0x7f9c4b9fed0a in MagickImageCommand MagickWand/magick-cli.c:796:5
    #12 0x7f9c4ba48ba1 in MagickCommandGenesis MagickWand/mogrify.c:185:14
    #13 0x526f95 in MagickMain utilities/magick.c:149:10
    #14 0x5268e1 in main utilities/magick.c:180:10
    #15 0x7f9c464bfb96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)

Indirect leak of 64 byte(s) in 1 object(s) allocated from:
    #0 0x4e6200 in __interceptor_posix_memalign (install/bin/magick+0x4e6200)
    #1 0x7f9c4c57d781 in AcquireSemaphoreMemory MagickCore/semaphore.c:154:7
    #2 0x7f9c4c57cfc3 in AcquireSemaphoreInfo MagickCore/semaphore.c:200:36
    #3 0x7f9c4c16b2f4 in AcquirePixelCache MagickCore/cache.c:229:25
    #4 0x7f9c4c16bf8d in ClonePixelCache MagickCore/cache.c:513:28
    #5 0x7f9c4c3eb59f in CloneImage MagickCore/image.c:910:22
    #6 0x7f9c4c5e8885 in ExtentImage MagickCore/transform.c:1134:16
    #7 0x7f9c4c1c5d00 in CompareImages MagickCore/compare.c:188:20
    #8 0x7f9c4bbb06f1 in CLIListOperatorImages MagickWand/operation.c:3880:22
    #9 0x7f9c4bbbc35e in CLIOption MagickWand/operation.c:5279:14
    #10 0x7f9c4b9fda99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
    #11 0x7f9c4b9fed0a in MagickImageCommand MagickWand/magick-cli.c:796:5
    #12 0x7f9c4ba48ba1 in MagickCommandGenesis MagickWand/mogrify.c:185:14
    #13 0x526f95 in MagickMain utilities/magick.c:149:10
    #14 0x5268e1 in main utilities/magick.c:180:10
    #15 0x7f9c464bfb96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)

Indirect leak of 64 byte(s) in 1 object(s) allocated from:
    #0 0x4e6200 in __interceptor_posix_memalign (install/bin/magick+0x4e6200)
    #1 0x7f9c4c57d781 in AcquireSemaphoreMemory MagickCore/semaphore.c:154:7
    #2 0x7f9c4c57cfc3 in AcquireSemaphoreInfo MagickCore/semaphore.c:200:36
    #3 0x7f9c4c594389 in NewSplayTree MagickCore/splay-tree.c:1159:25
    #4 0x7f9c4c593d24 in CloneSplayTree MagickCore/splay-tree.c:360:14
    #5 0x7f9c4c4698c0 in CloneImageOptions MagickCore/option.c:2144:27
    #6 0x7f9c4c3f2018 in CloneImageInfo MagickCore/image.c:1010:10
    #7 0x7f9c4c3e7678 in SyncImageSettings MagickCore/image.c:4242:21
    #8 0x7f9c4c3fee66 in SyncImagesSettings MagickCore/image.c:4000:12
    #9 0x7f9c4bbbc163 in CLIOption MagickWand/operation.c:5246:14
    #10 0x7f9c4b9fda99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
    #11 0x7f9c4b9fed0a in MagickImageCommand MagickWand/magick-cli.c:796:5
    #12 0x7f9c4ba48ba1 in MagickCommandGenesis MagickWand/mogrify.c:185:14
    #13 0x526f95 in MagickMain utilities/magick.c:149:10
    #14 0x5268e1 in main utilities/magick.c:180:10
    #15 0x7f9c464bfb96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)

Indirect leak of 64 byte(s) in 1 object(s) allocated from:
    #0 0x4e6200 in __interceptor_posix_memalign (install/bin/magick+0x4e6200)
    #1 0x7f9c4c437f26 in AcquireAlignedMemory MagickCore/memory.c:265:7
    #2 0x7f9c4c16b4e2 in AcquirePixelCacheNexus MagickCore/cache.c:267:29
    #3 0x7f9c4c16af8d in AcquirePixelCache MagickCore/cache.c:212:26
    #4 0x7f9c4c16bf8d in ClonePixelCache MagickCore/cache.c:513:28
    #5 0x7f9c4c3eb59f in CloneImage MagickCore/image.c:910:22
    #6 0x7f9c4c5e8885 in ExtentImage MagickCore/transform.c:1134:16
    #7 0x7f9c4c1c5d00 in CompareImages MagickCore/compare.c:188:20
    #8 0x7f9c4bbb06f1 in CLIListOperatorImages MagickWand/operation.c:3880:22
    #9 0x7f9c4bbbc35e in CLIOption MagickWand/operation.c:5279:14
    #10 0x7f9c4b9fda99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
    #11 0x7f9c4b9fed0a in MagickImageCommand MagickWand/magick-cli.c:796:5
    #12 0x7f9c4ba48ba1 in MagickCommandGenesis MagickWand/mogrify.c:185:14
    #13 0x526f95 in MagickMain utilities/magick.c:149:10
    #14 0x5268e1 in main utilities/magick.c:180:10
    #15 0x7f9c464bfb96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)

Indirect leak of 64 byte(s) in 2 object(s) allocated from:
    #0 0x4e5397 in __interceptor_malloc (install/bin/magick+0x4e5397)
    #1 0x7f9c4c438106 in AcquireMagickMemory MagickCore/memory.c:478:10
    #2 0x7f9c4c593033 in AddValueToSplayTree MagickCore/splay-tree.c:189:21
    #3 0x7f9c4c593f3c in CloneSplayTree MagickCore/splay-tree.c:372:12
    #4 0x7f9c4c4698c0 in CloneImageOptions MagickCore/option.c:2144:27
    #5 0x7f9c4c3f2018 in CloneImageInfo MagickCore/image.c:1010:10
    #6 0x7f9c4c3e7678 in SyncImageSettings MagickCore/image.c:4242:21
    #7 0x7f9c4c3fee66 in SyncImagesSettings MagickCore/image.c:4000:12
    #8 0x7f9c4bbbc163 in CLIOption MagickWand/operation.c:5246:14
    #9 0x7f9c4b9fda99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
    #10 0x7f9c4b9fed0a in MagickImageCommand MagickWand/magick-cli.c:796:5
    #11 0x7f9c4ba48ba1 in MagickCommandGenesis MagickWand/mogrify.c:185:14
    #12 0x526f95 in MagickMain utilities/magick.c:149:10
    #13 0x5268e1 in main utilities/magick.c:180:10
    #14 0x7f9c464bfb96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)

Indirect leak of 64 byte(s) in 1 object(s) allocated from:
    #0 0x4e6200 in __interceptor_posix_memalign (install/bin/magick+0x4e6200)
    #1 0x7f9c4c57d781 in AcquireSemaphoreMemory MagickCore/semaphore.c:154:7
    #2 0x7f9c4c57cfc3 in AcquireSemaphoreInfo MagickCore/semaphore.c:200:36
    #3 0x7f9c4c3ea99f in CloneImage MagickCore/image.c:871:26
    #4 0x7f9c4c5e8885 in ExtentImage MagickCore/transform.c:1134:16
    #5 0x7f9c4c1c5d00 in CompareImages MagickCore/compare.c:188:20
    #6 0x7f9c4bbb06f1 in CLIListOperatorImages MagickWand/operation.c:3880:22
    #7 0x7f9c4bbbc35e in CLIOption MagickWand/operation.c:5279:14
    #8 0x7f9c4b9fda99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
    #9 0x7f9c4b9fed0a in MagickImageCommand MagickWand/magick-cli.c:796:5
    #10 0x7f9c4ba48ba1 in MagickCommandGenesis MagickWand/mogrify.c:185:14
    #11 0x526f95 in MagickMain utilities/magick.c:149:10
    #12 0x5268e1 in main utilities/magick.c:180:10
    #13 0x7f9c464bfb96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)

Indirect leak of 64 byte(s) in 1 object(s) allocated from:
    #0 0x4e6200 in __interceptor_posix_memalign (install/bin/magick+0x4e6200)
    #1 0x7f9c4c57d781 in AcquireSemaphoreMemory MagickCore/semaphore.c:154:7
    #2 0x7f9c4c57cfc3 in AcquireSemaphoreInfo MagickCore/semaphore.c:200:36
    #3 0x7f9c4c14a1ae in GetBlobInfo MagickCore/blob.c:1745:24
    #4 0x7f9c4c149d6a in CloneBlobInfo MagickCore/blob.c:555:3
    #5 0x7f9c4c3ea808 in CloneImage MagickCore/image.c:867:25
    #6 0x7f9c4c5e8885 in ExtentImage MagickCore/transform.c:1134:16
    #7 0x7f9c4c1c5d00 in CompareImages MagickCore/compare.c:188:20
    #8 0x7f9c4bbb06f1 in CLIListOperatorImages MagickWand/operation.c:3880:22
    #9 0x7f9c4bbbc35e in CLIOption MagickWand/operation.c:5279:14
    #10 0x7f9c4b9fda99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
    #11 0x7f9c4b9fed0a in MagickImageCommand MagickWand/magick-cli.c:796:5
    #12 0x7f9c4ba48ba1 in MagickCommandGenesis MagickWand/mogrify.c:185:14
    #13 0x526f95 in MagickMain utilities/magick.c:149:10
    #14 0x5268e1 in main utilities/magick.c:180:10
    #15 0x7f9c464bfb96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)

Indirect leak of 64 byte(s) in 1 object(s) allocated from:
    #0 0x4e6200 in __interceptor_posix_memalign (install/bin/magick+0x4e6200)
    #1 0x7f9c4c57d781 in AcquireSemaphoreMemory MagickCore/semaphore.c:154:7
    #2 0x7f9c4c57cfc3 in AcquireSemaphoreInfo MagickCore/semaphore.c:200:36
    #3 0x7f9c4c594389 in NewSplayTree MagickCore/splay-tree.c:1159:25
    #4 0x7f9c4c593d24 in CloneSplayTree MagickCore/splay-tree.c:360:14
    #5 0x7f9c4c4c8ee3 in CloneImageProperties MagickCore/property.c:196:25
    #6 0x7f9c4c3e9f59 in CloneImage MagickCore/image.c:839:10
    #7 0x7f9c4c5e8885 in ExtentImage MagickCore/transform.c:1134:16
    #8 0x7f9c4c1c5d00 in CompareImages MagickCore/compare.c:188:20
    #9 0x7f9c4bbb06f1 in CLIListOperatorImages MagickWand/operation.c:3880:22
    #10 0x7f9c4bbbc35e in CLIOption MagickWand/operation.c:5279:14
    #11 0x7f9c4b9fda99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
    #12 0x7f9c4b9fed0a in MagickImageCommand MagickWand/magick-cli.c:796:5
    #13 0x7f9c4ba48ba1 in MagickCommandGenesis MagickWand/mogrify.c:185:14
    #14 0x526f95 in MagickMain utilities/magick.c:149:10
    #15 0x5268e1 in main utilities/magick.c:180:10
    #16 0x7f9c464bfb96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)

Indirect leak of 62 byte(s) in 3 object(s) allocated from:
    #0 0x4e5397 in __interceptor_malloc (install/bin/magick+0x4e5397)
    #1 0x7f9c4c438106 in AcquireMagickMemory MagickCore/memory.c:478:10
    #2 0x7f9c4c43816f in AcquireQuantumMemory MagickCore/memory.c:551:10
    #3 0x7f9c4c5cb9d3 in ConstantString MagickCore/string.c:713:26
    #4 0x7f9c4c593f26 in CloneSplayTree MagickCore/splay-tree.c:373:7
    #5 0x7f9c4c4c8ee3 in CloneImageProperties MagickCore/property.c:196:25
    #6 0x7f9c4c3e9f59 in CloneImage MagickCore/image.c:839:10
    #7 0x7f9c4c5e8885 in ExtentImage MagickCore/transform.c:1134:16
    #8 0x7f9c4c1c5d00 in CompareImages MagickCore/compare.c:188:20
    #9 0x7f9c4bbb06f1 in CLIListOperatorImages MagickWand/operation.c:3880:22
    #10 0x7f9c4bbbc35e in CLIOption MagickWand/operation.c:5279:14
    #11 0x7f9c4b9fda99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
    #12 0x7f9c4b9fed0a in MagickImageCommand MagickWand/magick-cli.c:796:5
    #13 0x7f9c4ba48ba1 in MagickCommandGenesis MagickWand/mogrify.c:185:14
    #14 0x526f95 in MagickMain utilities/magick.c:149:10
    #15 0x5268e1 in main utilities/magick.c:180:10
    #16 0x7f9c464bfb96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)

Indirect leak of 35 byte(s) in 3 object(s) allocated from:
    #0 0x4e5397 in __interceptor_malloc (install/bin/magick+0x4e5397)
    #1 0x7f9c4c438106 in AcquireMagickMemory MagickCore/memory.c:478:10
    #2 0x7f9c4c43816f in AcquireQuantumMemory MagickCore/memory.c:551:10
    #3 0x7f9c4c5cb9d3 in ConstantString MagickCore/string.c:713:26
    #4 0x7f9c4c593ea1 in CloneSplayTree MagickCore/splay-tree.c:372:43
    #5 0x7f9c4c4c8ee3 in CloneImageProperties MagickCore/property.c:196:25
    #6 0x7f9c4c3e9f59 in CloneImage MagickCore/image.c:839:10
    #7 0x7f9c4c5e8885 in ExtentImage MagickCore/transform.c:1134:16
    #8 0x7f9c4c1c5d00 in CompareImages MagickCore/compare.c:188:20
    #9 0x7f9c4bbb06f1 in CLIListOperatorImages MagickWand/operation.c:3880:22
    #10 0x7f9c4bbbc35e in CLIOption MagickWand/operation.c:5279:14
    #11 0x7f9c4b9fda99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
    #12 0x7f9c4b9fed0a in MagickImageCommand MagickWand/magick-cli.c:796:5
    #13 0x7f9c4ba48ba1 in MagickCommandGenesis MagickWand/mogrify.c:185:14
    #14 0x526f95 in MagickMain utilities/magick.c:149:10
    #15 0x5268e1 in main utilities/magick.c:180:10
    #16 0x7f9c464bfb96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)

Indirect leak of 16 byte(s) in 2 object(s) allocated from:
    #0 0x4e5397 in __interceptor_malloc (install/bin/magick+0x4e5397)
    #1 0x7f9c4c438106 in AcquireMagickMemory MagickCore/memory.c:478:10
    #2 0x7f9c4c43816f in AcquireQuantumMemory MagickCore/memory.c:551:10
    #3 0x7f9c4c5cb9d3 in ConstantString MagickCore/string.c:713:26
    #4 0x7f9c4c593ea1 in CloneSplayTree MagickCore/splay-tree.c:372:43
    #5 0x7f9c4c4698c0 in CloneImageOptions MagickCore/option.c:2144:27
    #6 0x7f9c4c3f2018 in CloneImageInfo MagickCore/image.c:1010:10
    #7 0x7f9c4c3e7678 in SyncImageSettings MagickCore/image.c:4242:21
    #8 0x7f9c4c3fee66 in SyncImagesSettings MagickCore/image.c:4000:12
    #9 0x7f9c4bbbc163 in CLIOption MagickWand/operation.c:5246:14
    #10 0x7f9c4b9fda99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
    #11 0x7f9c4b9fed0a in MagickImageCommand MagickWand/magick-cli.c:796:5
    #12 0x7f9c4ba48ba1 in MagickCommandGenesis MagickWand/mogrify.c:185:14
    #13 0x526f95 in MagickMain utilities/magick.c:149:10
    #14 0x5268e1 in main utilities/magick.c:180:10
    #15 0x7f9c464bfb96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)

Indirect leak of 7 byte(s) in 2 object(s) allocated from:
    #0 0x4e5397 in __interceptor_malloc (install/bin/magick+0x4e5397)
    #1 0x7f9c4c438106 in AcquireMagickMemory MagickCore/memory.c:478:10
    #2 0x7f9c4c43816f in AcquireQuantumMemory MagickCore/memory.c:551:10
    #3 0x7f9c4c5cb9d3 in ConstantString MagickCore/string.c:713:26
    #4 0x7f9c4c593f26 in CloneSplayTree MagickCore/splay-tree.c:373:7
    #5 0x7f9c4c4698c0 in CloneImageOptions MagickCore/option.c:2144:27
    #6 0x7f9c4c3f2018 in CloneImageInfo MagickCore/image.c:1010:10
    #7 0x7f9c4c3e7678 in SyncImageSettings MagickCore/image.c:4242:21
    #8 0x7f9c4c3fee66 in SyncImagesSettings MagickCore/image.c:4000:12
    #9 0x7f9c4bbbc163 in CLIOption MagickWand/operation.c:5246:14
    #10 0x7f9c4b9fda99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
    #11 0x7f9c4b9fed0a in MagickImageCommand MagickWand/magick-cli.c:796:5
    #12 0x7f9c4ba48ba1 in MagickCommandGenesis MagickWand/mogrify.c:185:14
    #13 0x526f95 in MagickMain utilities/magick.c:149:10
    #14 0x5268e1 in main utilities/magick.c:180:10
    #15 0x7f9c464bfb96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)

SUMMARY: AddressSanitizer: 6613792 byte(s) leaked in 32 allocation(s).

```

### System Configuration
<!-- Tell us about the environment where you are experiencing the bug -->

- ImageMagick version:
Version: ImageMagick 7.0.8-50 Q16 x86_64 2019-06-23 https://imagemagick.org

- Environment (Operating system, version and so on):
Description:	Ubuntu 18.04.1 LTS
Release:	18.04
Codename: bionic

- Additional information:
CC=clang-7 CXX=clang++-7 ./configure --disable-openmp
<!-- Thanks for reporting the issue to ImageMagick! -->



Comments:
Comment by urban-warrior on 2019-06-23 15:48:11+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. 


---

Comment by nohmask on 2019-07-08 01:53:13+00:00:
This was assigned CVE-2019-13309 and CVE-2019-13310.

Build script:
#!/bin/bash
# Default build script template for C/C++ projects
set -eu

# Define configuration options
CONFIG_OPTS="--disable-shared"
CMAKE_OPTS="-DCMAKE_BUILD_TYPE=Debug"
MAKE_OPTS="-j$(nproc)"
BUILD_DIR="build"

# 1. Run build preparation scripts if they exist
for prep_script in buildconf autogen.sh bootstrap; do
  if [ -x "$prep_script" ]; then
    echo "Running $prep_script..."
    ./$prep_script
    break
  elif [ -f "$prep_script" ]; then
    echo "Found $prep_script but it's not executable, setting permissions..."
    chmod +x $prep_script
    ./$prep_script
    break
  fi
done

# 2. Handle different build systems
if [ -f "configure" ]; then
  echo "Found configure script, running with options: $CONFIG_OPTS"
  ./configure $CONFIG_OPTS

  echo "Building with make $MAKE_OPTS"
  make $MAKE_OPTS
elif [ -f "CMakeLists.txt" ]; then
  echo "Found CMakeLists.txt, using CMake build system"
  mkdir -p $BUILD_DIR
  cd $BUILD_DIR
  cmake $CMAKE_OPTS ..
  make $MAKE_OPTS
elif [ -f "Makefile" ] || [ -f "makefile" ]; then
  echo "Found Makefile, building with make $MAKE_OPTS"
  make $MAKE_OPTS
elif [ -f "meson.build" ]; then
  echo "Found meson.build, using Meson build system"
  mkdir -p $BUILD_DIR
  meson setup $BUILD_DIR .
  cd $BUILD_DIR
  ninja
elif [ -f "GNUmakefile" ]; then
  echo "Found GNUmakefile, building with make $MAKE_OPTS"
  make $MAKE_OPTS
elif [ -d ".git" ] && [ -f "Makefile.am" ]; then
  echo "Found Makefile.am, running autoreconf"
  autoreconf -i
  ./configure $CONFIG_OPTS
  make $MAKE_OPTS
else
  echo "WARNING: No recognized build system found!"
  echo "Trying generic approach:"
  
  # Try to detect common source patterns and compile them
  if ls *.c >/dev/null 2>&1 || ls *.cpp >/dev/null 2>&1 || ls *.cc >/dev/null 2>&1; then
    echo "Found C/C++ source files, attempting direct compilation"
    if ls *.cpp >/dev/null 2>&1 || ls *.cc >/dev/null 2>&1; then
      CXX=${CXX:-g++}
      echo "Compiling C++ sources with $CXX"
      $CXX -g -O1 -fsanitize=address -fno-omit-frame-pointer -o main *.cpp *.cc 2>/dev/null || true
    elif ls *.c >/dev/null 2>&1; then
      CC=${CC:-gcc}
      echo "Compiling C sources with $CC"
      $CC -g -O1 -fsanitize=address -fno-omit-frame-pointer -o main *.c 2>/dev/null || true
    fi
  fi
fi

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

Additional files: