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

================= Bug Report (1/1) ==================
## Source: GitHub Issue
## URL: https://github.com/ImageMagick/ImageMagick/issues/1623
## Description:
Issue: ImageMagick/ImageMagick#1623
Title: memory leaks is detected at AcquireMagickMemory
State: closed
Created by: SuhwanSong
Created at: 2019-07-01 18:19:43+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 which are detected at AcquireMagickMemory.
This maybe relates with [#1616](https://github.com/ImageMagick/ImageMagick/issues/1616).

### 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 following cmd:
`magick -seed 0 -label "%r%W&%tZRD%r%A" -units PixelsPerCentimeter -caption "%s%m%w" "(" magick:logo +repage ")" "(" magick:granite -shade 13x85  ")" -compress RLE -combine -ift -complex magnitude-phase   tmp`

Here's Asan Log.
```
==26664==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 13504 byte(s) in 1 object(s) allocated from:
    #0 0x4e5397 in malloc (install/bin/magick+0x4e5397)
    #1 0x7f121156ec16 in AcquireMagickMemory MagickCore/memory.c:478:10
    #2 0x7f121151bb54 in AcquireCriticalMemory ./MagickCore/memory-private.h:64:10
    #3 0x7f1211520109 in CloneImage MagickCore/image.c:823:25
    #4 0x7f12112ce94b in CombineImages MagickCore/channel.c:520:17
    #5 0x7f1210cfc574 in CLIListOperatorImages MagickWand/operation.c:3848:22
    #6 0x7f1210d0839e in CLIOption MagickWand/operation.c:5282:14
    #7 0x7f1210b49a99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
    #8 0x7f1210b4ad0a in MagickImageCommand MagickWand/magick-cli.c:796:5
    #9 0x7f1210b94ba1 in MagickCommandGenesis MagickWand/mogrify.c:185:14
    #10 0x526f95 in MagickMain utilities/magick.c:149:10
    #11 0x5268e1 in main utilities/magick.c:180:10
    #12 0x7f120b60bb96 in __libc_start_main /build/glibc-OTsEL5/glibc-2.27/csu/../csu/libc-start.c:310

Indirect leak of 3686400 byte(s) in 1 object(s) allocated from:
    #0 0x4e6200 in posix_memalign (install/bin/magick+0x4e6200)
    #1 0x7f121156ea36 in AcquireAlignedMemory MagickCore/memory.c:265:7
    #2 0x7f12112b6ede in OpenPixelCache MagickCore/cache.c:3732:46
    #3 0x7f12112bd1c1 in GetImagePixelCache MagickCore/cache.c:1756:18
    #4 0x7f12112c35b9 in SyncImagePixelCache MagickCore/cache.c:5499:28
    #5 0x7f12115222c1 in SetImageStorageClass MagickCore/image.c:2627:10
    #6 0x7f12112ce980 in CombineImages MagickCore/channel.c:523:7
    #7 0x7f1210cfc574 in CLIListOperatorImages MagickWand/operation.c:3848:22
    #8 0x7f1210d0839e in CLIOption MagickWand/operation.c:5282:14
    #9 0x7f1210b49a99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
    #10 0x7f1210b4ad0a in MagickImageCommand MagickWand/magick-cli.c:796:5
    #11 0x7f1210b94ba1 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 0x7f120b60bb96 in __libc_start_main /build/glibc-OTsEL5/glibc-2.27/csu/../csu/libc-start.c:310

Indirect leak of 22616 byte(s) in 1 object(s) allocated from:
    #0 0x4e5397 in malloc (install/bin/magick+0x4e5397)
    #1 0x7f121156ec16 in AcquireMagickMemory MagickCore/memory.c:478:10
    #2 0x7f121156ec7f in AcquireQuantumMemory MagickCore/memory.c:551:10
    #3 0x7f121152153d in CloneImage MagickCore/image.c:879:43
    #4 0x7f12112ce94b in CombineImages MagickCore/channel.c:520:17
    #5 0x7f1210cfc574 in CLIListOperatorImages MagickWand/operation.c:3848:22
    #6 0x7f1210d0839e in CLIOption MagickWand/operation.c:5282:14
    #7 0x7f1210b49a99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
    #8 0x7f1210b4ad0a in MagickImageCommand MagickWand/magick-cli.c:796:5
    #9 0x7f1210b94ba1 in MagickCommandGenesis MagickWand/mogrify.c:185:14
    #10 0x526f95 in MagickMain utilities/magick.c:149:10
    #11 0x5268e1 in main utilities/magick.c:180:10
    #12 0x7f120b60bb96 in __libc_start_main /build/glibc-OTsEL5/glibc-2.27/csu/../csu/libc-start.c:310

Indirect leak of 13024 byte(s) in 1 object(s) allocated from:
    #0 0x4e5397 in malloc (install/bin/magick+0x4e5397)
    #1 0x7f121156ec16 in AcquireMagickMemory MagickCore/memory.c:478:10
    #2 0x7f121151bb54 in AcquireCriticalMemory ./MagickCore/memory-private.h:64:10
    #3 0x7f121151e193 in AcquireImageInfo MagickCore/image.c:350:28
    #4 0x7f1211526f53 in CloneImageInfo MagickCore/image.c:945:14
    #5 0x7f121151e0b8 in SyncImageSettings MagickCore/image.c:4242:21
    #6 0x7f12115358a6 in SyncImagesSettings MagickCore/image.c:4000:12
    #7 0x7f1210d081a3 in CLIOption MagickWand/operation.c:5249:14
    #8 0x7f1210b49a99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
    #9 0x7f1210b4ad0a in MagickImageCommand MagickWand/magick-cli.c:796:5
    #10 0x7f1210b94ba1 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 0x7f120b60bb96 in __libc_start_main /build/glibc-OTsEL5/glibc-2.27/csu/../csu/libc-start.c:310

Indirect leak of 9152 byte(s) in 1 object(s) allocated from:
    #0 0x4e6200 in posix_memalign (install/bin/magick+0x4e6200)
    #1 0x7f121156ea36 in AcquireAlignedMemory MagickCore/memory.c:265:7
    #2 0x7f12112a11d4 in AcquirePixelCache MagickCore/cache.c:195:28
    #3 0x7f12112a275d in ClonePixelCache MagickCore/cache.c:515:28
    #4 0x7f12112bcf3b in GetImagePixelCache MagickCore/cache.c:1724:29
    #5 0x7f12112c35b9 in SyncImagePixelCache MagickCore/cache.c:5499:28
    #6 0x7f12115222c1 in SetImageStorageClass MagickCore/image.c:2627:10
    #7 0x7f12112ce980 in CombineImages MagickCore/channel.c:523:7
    #8 0x7f1210cfc574 in CLIListOperatorImages MagickWand/operation.c:3848:22
    #9 0x7f1210d0839e in CLIOption MagickWand/operation.c:5282:14
    #10 0x7f1210b49a99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
    #11 0x7f1210b4ad0a in MagickImageCommand MagickWand/magick-cli.c:796:5
    #12 0x7f1210b94ba1 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 0x7f120b60bb96 in __libc_start_main /build/glibc-OTsEL5/glibc-2.27/csu/../csu/libc-start.c:310

Indirect leak of 512 byte(s) in 1 object(s) allocated from:
    #0 0x4e5397 in malloc (install/bin/magick+0x4e5397)
    #1 0x7f121156ec16 in AcquireMagickMemory MagickCore/memory.c:478:10
    #2 0x7f121156ec7f in AcquireQuantumMemory MagickCore/memory.c:551:10
    #3 0x7f12115afa4a in AcquirePixelChannelMap MagickCore/pixel.c:101:35
    #4 0x7f12115afc24 in ClonePixelChannelMap MagickCore/pixel.c:139:13
    #5 0x7f1211520d8f in CloneImage MagickCore/image.c:849:28
    #6 0x7f12112ce94b in CombineImages MagickCore/channel.c:520:17
    #7 0x7f1210cfc574 in CLIListOperatorImages MagickWand/operation.c:3848:22
    #8 0x7f1210d0839e in CLIOption MagickWand/operation.c:5282:14
    #9 0x7f1210b49a99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
    #10 0x7f1210b4ad0a in MagickImageCommand MagickWand/magick-cli.c:796:5
    #11 0x7f1210b94ba1 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 0x7f120b60bb96 in __libc_start_main /build/glibc-OTsEL5/glibc-2.27/csu/../csu/libc-start.c:310

Indirect leak of 288 byte(s) in 1 object(s) allocated from:
    #0 0x4e5397 in malloc (install/bin/magick+0x4e5397)
    #1 0x7f121156ec16 in AcquireMagickMemory MagickCore/memory.c:478:10
    #2 0x7f121127eb74 in AcquireCriticalMemory ./MagickCore/memory-private.h:64:10
    #3 0x7f121128064d in CloneBlobInfo MagickCore/blob.c:554:27
    #4 0x7f1211521248 in CloneImage MagickCore/image.c:867:25
    #5 0x7f12112ce94b in CombineImages MagickCore/channel.c:520:17
    #6 0x7f1210cfc574 in CLIListOperatorImages MagickWand/operation.c:3848:22
    #7 0x7f1210d0839e in CLIOption MagickWand/operation.c:5282:14
    #8 0x7f1210b49a99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
    #9 0x7f1210b4ad0a in MagickImageCommand MagickWand/magick-cli.c:796:5
    #10 0x7f1210b94ba1 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 0x7f120b60bb96 in __libc_start_main /build/glibc-OTsEL5/glibc-2.27/csu/../csu/libc-start.c:310

Indirect leak of 192 byte(s) in 1 object(s) allocated from:
    #0 0x4e5397 in malloc (install/bin/magick+0x4e5397)
    #1 0x7f121156ec16 in AcquireMagickMemory MagickCore/memory.c:478:10
    #2 0x7f121156ec7f in AcquireQuantumMemory MagickCore/memory.c:551:10
    #3 0x7f12112a1daf in AcquirePixelCacheNexus MagickCore/cache.c:271:29
    #4 0x7f12112a175d in AcquirePixelCache MagickCore/cache.c:212:26
    #5 0x7f12112a275d in ClonePixelCache MagickCore/cache.c:515:28
    #6 0x7f12112bcf3b in GetImagePixelCache MagickCore/cache.c:1724:29
    #7 0x7f12112c35b9 in SyncImagePixelCache MagickCore/cache.c:5499:28
    #8 0x7f12115222c1 in SetImageStorageClass MagickCore/image.c:2627:10
    #9 0x7f12112ce980 in CombineImages MagickCore/channel.c:523:7
    #10 0x7f1210cfc574 in CLIListOperatorImages MagickWand/operation.c:3848:22
    #11 0x7f1210d0839e in CLIOption MagickWand/operation.c:5282:14
    #12 0x7f1210b49a99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
    #13 0x7f1210b4ad0a in MagickImageCommand MagickWand/magick-cli.c:796:5
    #14 0x7f1210b94ba1 in MagickCommandGenesis MagickWand/mogrify.c:185:14
    #15 0x526f95 in MagickMain utilities/magick.c:149:10
    #16 0x5268e1 in main utilities/magick.c:180:10
    #17 0x7f120b60bb96 in __libc_start_main /build/glibc-OTsEL5/glibc-2.27/csu/../csu/libc-start.c:310

Indirect leak of 128 byte(s) in 4 object(s) allocated from:
    #0 0x4e5397 in malloc (install/bin/magick+0x4e5397)
    #1 0x7f121156ec16 in AcquireMagickMemory MagickCore/memory.c:478:10
    #2 0x7f12116c9dd3 in AddValueToSplayTree MagickCore/splay-tree.c:189:21
    #3 0x7f12116cacdc in CloneSplayTree MagickCore/splay-tree.c:372:12
    #4 0x7f12115a03d0 in CloneImageOptions MagickCore/option.c:2144:27
    #5 0x7f1211528a58 in CloneImageInfo MagickCore/image.c:1010:10
    #6 0x7f121151e0b8 in SyncImageSettings MagickCore/image.c:4242:21
    #7 0x7f12115358a6 in SyncImagesSettings MagickCore/image.c:4000:12
    #8 0x7f1210d081a3 in CLIOption MagickWand/operation.c:5249:14
    #9 0x7f1210b49a99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
    #10 0x7f1210b4ad0a in MagickImageCommand MagickWand/magick-cli.c:796:5
    #11 0x7f1210b94ba1 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 0x7f120b60bb96 in __libc_start_main /build/glibc-OTsEL5/glibc-2.27/csu/../csu/libc-start.c:310

Indirect leak of 128 byte(s) in 4 object(s) allocated from:
    #0 0x4e5397 in malloc (install/bin/magick+0x4e5397)
    #1 0x7f121156ec16 in AcquireMagickMemory MagickCore/memory.c:478:10
    #2 0x7f12116c9dd3 in AddValueToSplayTree MagickCore/splay-tree.c:189:21
    #3 0x7f12116cacdc in CloneSplayTree MagickCore/splay-tree.c:372:12
    #4 0x7f12115ff9f3 in CloneImageProperties MagickCore/property.c:196:25
    #5 0x7f1211520999 in CloneImage MagickCore/image.c:839:10
    #6 0x7f12112ce94b in CombineImages MagickCore/channel.c:520:17
    #7 0x7f1210cfc574 in CLIListOperatorImages MagickWand/operation.c:3848:22
    #8 0x7f1210d0839e in CLIOption MagickWand/operation.c:5282:14
    #9 0x7f1210b49a99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
    #10 0x7f1210b4ad0a in MagickImageCommand MagickWand/magick-cli.c:796:5
    #11 0x7f1210b94ba1 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 0x7f120b60bb96 in __libc_start_main /build/glibc-OTsEL5/glibc-2.27/csu/../csu/libc-start.c:310

Indirect leak of 115 byte(s) in 4 object(s) allocated from:
    #0 0x4e5397 in malloc (install/bin/magick+0x4e5397)
    #1 0x7f121156ec16 in AcquireMagickMemory MagickCore/memory.c:478:10
    #2 0x7f121156ec7f in AcquireQuantumMemory MagickCore/memory.c:551:10
    #3 0x7f12117027c3 in ConstantString MagickCore/string.c:713:26
    #4 0x7f12116cacc6 in CloneSplayTree MagickCore/splay-tree.c:373:7
    #5 0x7f12115ff9f3 in CloneImageProperties MagickCore/property.c:196:25
    #6 0x7f1211520999 in CloneImage MagickCore/image.c:839:10
    #7 0x7f12112ce94b in CombineImages MagickCore/channel.c:520:17
    #8 0x7f1210cfc574 in CLIListOperatorImages MagickWand/operation.c:3848:22
    #9 0x7f1210d0839e in CLIOption MagickWand/operation.c:5282:14
    #10 0x7f1210b49a99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
    #11 0x7f1210b4ad0a in MagickImageCommand MagickWand/magick-cli.c:796:5
    #12 0x7f1210b94ba1 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 0x7f120b60bb96 in __libc_start_main /build/glibc-OTsEL5/glibc-2.27/csu/../csu/libc-start.c:310

Indirect leak of 88 byte(s) in 1 object(s) allocated from:
    #0 0x4e5397 in malloc (install/bin/magick+0x4e5397)
    #1 0x7f121156ec16 in AcquireMagickMemory MagickCore/memory.c:478:10
    #2 0x7f12116cee24 in AcquireCriticalMemory ./MagickCore/memory-private.h:64:10
    #3 0x7f12116caeb5 in NewSplayTree MagickCore/splay-tree.c:1148:32
    #4 0x7f12116caac4 in CloneSplayTree MagickCore/splay-tree.c:360:14
    #5 0x7f12115ff9f3 in CloneImageProperties MagickCore/property.c:196:25
    #6 0x7f1211520999 in CloneImage MagickCore/image.c:839:10
    #7 0x7f12112ce94b in CombineImages MagickCore/channel.c:520:17
    #8 0x7f1210cfc574 in CLIListOperatorImages MagickWand/operation.c:3848:22
    #9 0x7f1210d0839e in CLIOption MagickWand/operation.c:5282:14
    #10 0x7f1210b49a99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
    #11 0x7f1210b4ad0a in MagickImageCommand MagickWand/magick-cli.c:796:5
    #12 0x7f1210b94ba1 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 0x7f120b60bb96 in __libc_start_main /build/glibc-OTsEL5/glibc-2.27/csu/../csu/libc-start.c:310

Indirect leak of 88 byte(s) in 1 object(s) allocated from:
    #0 0x4e5397 in malloc (install/bin/magick+0x4e5397)
    #1 0x7f121156ec16 in AcquireMagickMemory MagickCore/memory.c:478:10
    #2 0x7f12116cee24 in AcquireCriticalMemory ./MagickCore/memory-private.h:64:10
    #3 0x7f12116caeb5 in NewSplayTree MagickCore/splay-tree.c:1148:32
    #4 0x7f12116caac4 in CloneSplayTree MagickCore/splay-tree.c:360:14
    #5 0x7f12115a03d0 in CloneImageOptions MagickCore/option.c:2144:27
    #6 0x7f1211528a58 in CloneImageInfo MagickCore/image.c:1010:10
    #7 0x7f121151e0b8 in SyncImageSettings MagickCore/image.c:4242:21
    #8 0x7f12115358a6 in SyncImagesSettings MagickCore/image.c:4000:12
    #9 0x7f1210d081a3 in CLIOption MagickWand/operation.c:5249:14
    #10 0x7f1210b49a99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
    #11 0x7f1210b4ad0a in MagickImageCommand MagickWand/magick-cli.c:796:5
    #12 0x7f1210b94ba1 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 0x7f120b60bb96 in __libc_start_main /build/glibc-OTsEL5/glibc-2.27/csu/../csu/libc-start.c:310

Indirect leak of 88 byte(s) in 1 object(s) allocated from:
    #0 0x4e5397 in malloc (install/bin/magick+0x4e5397)
    #1 0x7f121156ec16 in AcquireMagickMemory MagickCore/memory.c:478:10
    #2 0x7f12116cee24 in AcquireCriticalMemory ./MagickCore/memory-private.h:64:10
    #3 0x7f12116caeb5 in NewSplayTree MagickCore/splay-tree.c:1148:32
    #4 0x7f12116caac4 in CloneSplayTree MagickCore/splay-tree.c:360:14
    #5 0x7f1211272c4a in CloneImageArtifacts MagickCore/artifact.c:118:24
    #6 0x7f12115209ac in CloneImage MagickCore/image.c:840:10
    #7 0x7f12112ce94b in CombineImages MagickCore/channel.c:520:17
    #8 0x7f1210cfc574 in CLIListOperatorImages MagickWand/operation.c:3848:22
    #9 0x7f1210d0839e in CLIOption MagickWand/operation.c:5282:14
    #10 0x7f1210b49a99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
    #11 0x7f1210b4ad0a in MagickImageCommand MagickWand/magick-cli.c:796:5
    #12 0x7f1210b94ba1 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 0x7f120b60bb96 in __libc_start_main /build/glibc-OTsEL5/glibc-2.27/csu/../csu/libc-start.c:310

Indirect leak of 64 byte(s) in 1 object(s) allocated from:
    #0 0x4e6200 in posix_memalign (install/bin/magick+0x4e6200)
    #1 0x7f12116b4521 in AcquireSemaphoreMemory MagickCore/semaphore.c:154:7
    #2 0x7f12116b3d63 in AcquireSemaphoreInfo MagickCore/semaphore.c:200:36
    #3 0x7f12112a1ac4 in AcquirePixelCache MagickCore/cache.c:229:25
    #4 0x7f12112a275d in ClonePixelCache MagickCore/cache.c:515:28
    #5 0x7f12112bcf3b in GetImagePixelCache MagickCore/cache.c:1724:29
    #6 0x7f12112c35b9 in SyncImagePixelCache MagickCore/cache.c:5499:28
    #7 0x7f12115222c1 in SetImageStorageClass MagickCore/image.c:2627:10
    #8 0x7f12112ce980 in CombineImages MagickCore/channel.c:523:7
    #9 0x7f1210cfc574 in CLIListOperatorImages MagickWand/operation.c:3848:22
    #10 0x7f1210d0839e in CLIOption MagickWand/operation.c:5282:14
    #11 0x7f1210b49a99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
    #12 0x7f1210b4ad0a in MagickImageCommand MagickWand/magick-cli.c:796:5
    #13 0x7f1210b94ba1 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 0x7f120b60bb96 in __libc_start_main /build/glibc-OTsEL5/glibc-2.27/csu/../csu/libc-start.c:310

Indirect leak of 64 byte(s) in 1 object(s) allocated from:
    #0 0x4e6200 in posix_memalign (install/bin/magick+0x4e6200)
    #1 0x7f121156ea36 in AcquireAlignedMemory MagickCore/memory.c:265:7
    #2 0x7f12112a1cb2 in AcquirePixelCacheNexus MagickCore/cache.c:267:29
    #3 0x7f12112a175d in AcquirePixelCache MagickCore/cache.c:212:26
    #4 0x7f12112a275d in ClonePixelCache MagickCore/cache.c:515:28
    #5 0x7f12112bcf3b in GetImagePixelCache MagickCore/cache.c:1724:29
    #6 0x7f12112c35b9 in SyncImagePixelCache MagickCore/cache.c:5499:28
    #7 0x7f12115222c1 in SetImageStorageClass MagickCore/image.c:2627:10
    #8 0x7f12112ce980 in CombineImages MagickCore/channel.c:523:7
    #9 0x7f1210cfc574 in CLIListOperatorImages MagickWand/operation.c:3848:22
    #10 0x7f1210d0839e in CLIOption MagickWand/operation.c:5282:14
    #11 0x7f1210b49a99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
    #12 0x7f1210b4ad0a in MagickImageCommand MagickWand/magick-cli.c:796:5
    #13 0x7f1210b94ba1 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 0x7f120b60bb96 in __libc_start_main /build/glibc-OTsEL5/glibc-2.27/csu/../csu/libc-start.c:310

Indirect leak of 64 byte(s) in 1 object(s) allocated from:
    #0 0x4e6200 in posix_memalign (install/bin/magick+0x4e6200)
    #1 0x7f12116b4521 in AcquireSemaphoreMemory MagickCore/semaphore.c:154:7
    #2 0x7f12116b3d63 in AcquireSemaphoreInfo MagickCore/semaphore.c:200:36
    #3 0x7f12115213df in CloneImage MagickCore/image.c:871:26
    #4 0x7f12112ce94b in CombineImages MagickCore/channel.c:520:17
    #5 0x7f1210cfc574 in CLIListOperatorImages MagickWand/operation.c:3848:22
    #6 0x7f1210d0839e in CLIOption MagickWand/operation.c:5282:14
    #7 0x7f1210b49a99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
    #8 0x7f1210b4ad0a in MagickImageCommand MagickWand/magick-cli.c:796:5
    #9 0x7f1210b94ba1 in MagickCommandGenesis MagickWand/mogrify.c:185:14
    #10 0x526f95 in MagickMain utilities/magick.c:149:10
    #11 0x5268e1 in main utilities/magick.c:180:10
    #12 0x7f120b60bb96 in __libc_start_main /build/glibc-OTsEL5/glibc-2.27/csu/../csu/libc-start.c:310

Indirect leak of 64 byte(s) in 1 object(s) allocated from:
    #0 0x4e6200 in posix_memalign (install/bin/magick+0x4e6200)
    #1 0x7f12116b4521 in AcquireSemaphoreMemory MagickCore/semaphore.c:154:7
    #2 0x7f12116b3d63 in AcquireSemaphoreInfo MagickCore/semaphore.c:200:36
    #3 0x7f1211280a9e in GetBlobInfo MagickCore/blob.c:1745:24
    #4 0x7f121128065a in CloneBlobInfo MagickCore/blob.c:555:3
    #5 0x7f1211521248 in CloneImage MagickCore/image.c:867:25
    #6 0x7f12112ce94b in CombineImages MagickCore/channel.c:520:17
    #7 0x7f1210cfc574 in CLIListOperatorImages MagickWand/operation.c:3848:22
    #8 0x7f1210d0839e in CLIOption MagickWand/operation.c:5282:14
    #9 0x7f1210b49a99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
    #10 0x7f1210b4ad0a in MagickImageCommand MagickWand/magick-cli.c:796:5
    #11 0x7f1210b94ba1 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 0x7f120b60bb96 in __libc_start_main /build/glibc-OTsEL5/glibc-2.27/csu/../csu/libc-start.c:310

Indirect leak of 64 byte(s) in 1 object(s) allocated from:
    #0 0x4e6200 in posix_memalign (install/bin/magick+0x4e6200)
    #1 0x7f12116b4521 in AcquireSemaphoreMemory MagickCore/semaphore.c:154:7
    #2 0x7f12116b3d63 in AcquireSemaphoreInfo MagickCore/semaphore.c:200:36
    #3 0x7f12116cb129 in NewSplayTree MagickCore/splay-tree.c:1159:25
    #4 0x7f12116caac4 in CloneSplayTree MagickCore/splay-tree.c:360:14
    #5 0x7f1211272c4a in CloneImageArtifacts MagickCore/artifact.c:118:24
    #6 0x7f12115209ac in CloneImage MagickCore/image.c:840:10
    #7 0x7f12112ce94b in CombineImages MagickCore/channel.c:520:17
    #8 0x7f1210cfc574 in CLIListOperatorImages MagickWand/operation.c:3848:22
    #9 0x7f1210d0839e in CLIOption MagickWand/operation.c:5282:14
    #10 0x7f1210b49a99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
    #11 0x7f1210b4ad0a in MagickImageCommand MagickWand/magick-cli.c:796:5
    #12 0x7f1210b94ba1 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 0x7f120b60bb96 in __libc_start_main /build/glibc-OTsEL5/glibc-2.27/csu/../csu/libc-start.c:310

Indirect leak of 64 byte(s) in 1 object(s) allocated from:
    #0 0x4e6200 in posix_memalign (install/bin/magick+0x4e6200)
    #1 0x7f12116b4521 in AcquireSemaphoreMemory MagickCore/semaphore.c:154:7
    #2 0x7f12116b3d63 in AcquireSemaphoreInfo MagickCore/semaphore.c:200:36
    #3 0x7f12116cb129 in NewSplayTree MagickCore/splay-tree.c:1159:25
    #4 0x7f12116caac4 in CloneSplayTree MagickCore/splay-tree.c:360:14
    #5 0x7f12115ff9f3 in CloneImageProperties MagickCore/property.c:196:25
    #6 0x7f1211520999 in CloneImage MagickCore/image.c:839:10
    #7 0x7f12112ce94b in CombineImages MagickCore/channel.c:520:17
    #8 0x7f1210cfc574 in CLIListOperatorImages MagickWand/operation.c:3848:22
    #9 0x7f1210d0839e in CLIOption MagickWand/operation.c:5282:14
    #10 0x7f1210b49a99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
    #11 0x7f1210b4ad0a in MagickImageCommand MagickWand/magick-cli.c:796:5
    #12 0x7f1210b94ba1 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 0x7f120b60bb96 in __libc_start_main /build/glibc-OTsEL5/glibc-2.27/csu/../csu/libc-start.c:310

Indirect leak of 64 byte(s) in 1 object(s) allocated from:
    #0 0x4e6200 in posix_memalign (install/bin/magick+0x4e6200)
    #1 0x7f12116b4521 in AcquireSemaphoreMemory MagickCore/semaphore.c:154:7
    #2 0x7f12116b3d63 in AcquireSemaphoreInfo MagickCore/semaphore.c:200:36
    #3 0x7f12116cb129 in NewSplayTree MagickCore/splay-tree.c:1159:25
    #4 0x7f12116caac4 in CloneSplayTree MagickCore/splay-tree.c:360:14
    #5 0x7f12115a03d0 in CloneImageOptions MagickCore/option.c:2144:27
    #6 0x7f1211528a58 in CloneImageInfo MagickCore/image.c:1010:10
    #7 0x7f121151e0b8 in SyncImageSettings MagickCore/image.c:4242:21
    #8 0x7f12115358a6 in SyncImagesSettings MagickCore/image.c:4000:12
    #9 0x7f1210d081a3 in CLIOption MagickWand/operation.c:5249:14
    #10 0x7f1210b49a99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
    #11 0x7f1210b4ad0a in MagickImageCommand MagickWand/magick-cli.c:796:5
    #12 0x7f1210b94ba1 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 0x7f120b60bb96 in __libc_start_main /build/glibc-OTsEL5/glibc-2.27/csu/../csu/libc-start.c:310

Indirect leak of 64 byte(s) in 1 object(s) allocated from:
    #0 0x4e6200 in posix_memalign (install/bin/magick+0x4e6200)
    #1 0x7f12116b4521 in AcquireSemaphoreMemory MagickCore/semaphore.c:154:7
    #2 0x7f12116b3d63 in AcquireSemaphoreInfo MagickCore/semaphore.c:200:36
    #3 0x7f12112a1b53 in AcquirePixelCache MagickCore/cache.c:231:30
    #4 0x7f12112a275d in ClonePixelCache MagickCore/cache.c:515:28
    #5 0x7f12112bcf3b in GetImagePixelCache MagickCore/cache.c:1724:29
    #6 0x7f12112c35b9 in SyncImagePixelCache MagickCore/cache.c:5499:28
    #7 0x7f12115222c1 in SetImageStorageClass MagickCore/image.c:2627:10
    #8 0x7f12112ce980 in CombineImages MagickCore/channel.c:523:7
    #9 0x7f1210cfc574 in CLIListOperatorImages MagickWand/operation.c:3848:22
    #10 0x7f1210d0839e in CLIOption MagickWand/operation.c:5282:14
    #11 0x7f1210b49a99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
    #12 0x7f1210b4ad0a in MagickImageCommand MagickWand/magick-cli.c:796:5
    #13 0x7f1210b94ba1 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 0x7f120b60bb96 in __libc_start_main /build/glibc-OTsEL5/glibc-2.27/csu/../csu/libc-start.c:310

Indirect leak of 46 byte(s) in 4 object(s) allocated from:
    #0 0x4e5397 in malloc (install/bin/magick+0x4e5397)
    #1 0x7f121156ec16 in AcquireMagickMemory MagickCore/memory.c:478:10
    #2 0x7f121156ec7f in AcquireQuantumMemory MagickCore/memory.c:551:10
    #3 0x7f12117027c3 in ConstantString MagickCore/string.c:713:26
    #4 0x7f12116cacc6 in CloneSplayTree MagickCore/splay-tree.c:373:7
    #5 0x7f12115a03d0 in CloneImageOptions MagickCore/option.c:2144:27
    #6 0x7f1211528a58 in CloneImageInfo MagickCore/image.c:1010:10
    #7 0x7f121151e0b8 in SyncImageSettings MagickCore/image.c:4242:21
    #8 0x7f12115358a6 in SyncImagesSettings MagickCore/image.c:4000:12
    #9 0x7f1210d081a3 in CLIOption MagickWand/operation.c:5249:14
    #10 0x7f1210b49a99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
    #11 0x7f1210b4ad0a in MagickImageCommand MagickWand/magick-cli.c:796:5
    #12 0x7f1210b94ba1 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 0x7f120b60bb96 in __libc_start_main /build/glibc-OTsEL5/glibc-2.27/csu/../csu/libc-start.c:310

Indirect leak of 38 byte(s) in 4 object(s) allocated from:
    #0 0x4e5397 in malloc (install/bin/magick+0x4e5397)
    #1 0x7f121156ec16 in AcquireMagickMemory MagickCore/memory.c:478:10
    #2 0x7f121156ec7f in AcquireQuantumMemory MagickCore/memory.c:551:10
    #3 0x7f12117027c3 in ConstantString MagickCore/string.c:713:26
    #4 0x7f12116cac41 in CloneSplayTree MagickCore/splay-tree.c:372:43
    #5 0x7f12115ff9f3 in CloneImageProperties MagickCore/property.c:196:25
    #6 0x7f1211520999 in CloneImage MagickCore/image.c:839:10
    #7 0x7f12112ce94b in CombineImages MagickCore/channel.c:520:17
    #8 0x7f1210cfc574 in CLIListOperatorImages MagickWand/operation.c:3848:22
    #9 0x7f1210d0839e in CLIOption MagickWand/operation.c:5282:14
    #10 0x7f1210b49a99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
    #11 0x7f1210b4ad0a in MagickImageCommand MagickWand/magick-cli.c:796:5
    #12 0x7f1210b94ba1 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 0x7f120b60bb96 in __libc_start_main /build/glibc-OTsEL5/glibc-2.27/csu/../csu/libc-start.c:310

Indirect leak of 29 byte(s) in 4 object(s) allocated from:
    #0 0x4e5397 in malloc (install/bin/magick+0x4e5397)
    #1 0x7f121156ec16 in AcquireMagickMemory MagickCore/memory.c:478:10
    #2 0x7f121156ec7f in AcquireQuantumMemory MagickCore/memory.c:551:10
    #3 0x7f12117027c3 in ConstantString MagickCore/string.c:713:26
    #4 0x7f12116cac41 in CloneSplayTree MagickCore/splay-tree.c:372:43
    #5 0x7f12115a03d0 in CloneImageOptions MagickCore/option.c:2144:27
    #6 0x7f1211528a58 in CloneImageInfo MagickCore/image.c:1010:10
    #7 0x7f121151e0b8 in SyncImageSettings MagickCore/image.c:4242:21
    #8 0x7f12115358a6 in SyncImagesSettings MagickCore/image.c:4000:12
    #9 0x7f1210d081a3 in CLIOption MagickWand/operation.c:5249:14
    #10 0x7f1210b49a99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
    #11 0x7f1210b4ad0a in MagickImageCommand MagickWand/magick-cli.c:796:5
    #12 0x7f1210b94ba1 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 0x7f120b60bb96 in __libc_start_main /build/glibc-OTsEL5/glibc-2.27/csu/../csu/libc-start.c:310

SUMMARY: AddressSanitizer: 3746948 byte(s) leaked in 43 allocation(s).

```

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

- ImageMagick version:
ImageMagick 7.0.8-52 Q16 x86_64 2019-07-02 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 --without-png
and I also tested on Ubuntu 16.04 with clang-3.8 and gcc-5.

<!-- Thanks for reporting the issue to ImageMagick! -->



Comments:
Comment by urban-warrior on 2019-07-01 23:22:28+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:55:23+00:00:
This was assigned CVE-2019-13311.

---

Comment by fmw42 on 2019-07-08 02:41:36+00:00:
Why was this sent 18 times?

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 6a584be1f6631cc4f8d95da54834c931776541f2
WORKDIR $SRC/imagemagick
COPY build.sh $SRC/

Additional files: