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

================= Bug Report (1/1) ==================
## Source: GitHub Issue
## URL: https://github.com/ImageMagick/ImageMagick/issues/1604
## Description:
Issue: ImageMagick/ImageMagick#1604
Title: Direct memory leaks in AcquireMagickMemory and indirect memory leaks 
State: closed
Created by: SuhwanSong
Created at: 2019-06-18 17:22:26+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're a direct memory leaks in AcquireMagickMemory of MagickCore/memory.c:478:10 and 
many indirect memory leaks.

### 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 "(" magick:netscape +repage ")" "(" magick:granite +repage ")" -append -fft -compare   tmp`

and this cmd also can trigger them.
cmd:
`magick -seed 0 -bias 0% "(" magick:rose +repage ")" "(" magick:rose -despeckle -threshold 26 -wave 55x83  ")" -sampling-factor 3.65x3.408 -channel RGBA -compare -mosaic -compare   tmp`

Here's ASAN result.

```
==5674==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 0x7fdfed7f4146 in AcquireMagickMemory MagickCore/memory.c:478:10
    #2 0x7fdfed7a1154 in AcquireCriticalMemory ./MagickCore/memory-private.h:64:10
    #3 0x7fdfed7a5709 in CloneImage MagickCore/image.c:823:25
    #4 0x7fdfed7a4a81 in AppendImages MagickCore/image.c:520:16
    #5 0x7fdfecf6bd2d in CLIListOperatorImages MagickWand/operation.c:3795:22
    #6 0x7fdfecf7834e in CLIOption MagickWand/operation.c:5276:14
    #7 0x7fdfecdb9a99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
    #8 0x7fdfecdbad0a in MagickImageCommand MagickWand/magick-cli.c:796:5
    #9 0x7fdfece04ba1 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 0x7fdfe787bb96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)

Indirect leak of 940032 byte(s) in 1 object(s) allocated from:
    #0 0x4e6200 in __interceptor_posix_memalign (install/bin/magick+0x4e6200)
    #1 0x7fdfed7f3f66 in AcquireAlignedMemory MagickCore/memory.c:265:7
    #2 0x7fdfed53c6ac in OpenPixelCache MagickCore/cache.c:3728:46
    #3 0x7fdfed542991 in GetImagePixelCache MagickCore/cache.c:1754:18
    #4 0x7fdfed52a330 in QueueAuthenticPixelCacheNexus MagickCore/cache.c:4156:28
    #5 0x7fdfed52a001 in GetAuthenticPixelCacheNexus MagickCore/cache.c:1324:10
    #6 0x7fdfed54ca4e in GetCacheViewAuthenticPixels MagickCore/cache-view.c:312:10
    #7 0x7fdfed7b43e1 in SetImageAlpha MagickCore/image.c:2372:7
    #8 0x7fdfed8356d5 in ConformPixelInfo MagickCore/pixel.c:235:12
    #9 0x7fdfed7a84e7 in SetImageBackgroundColor MagickCore/image.c:2441:3
    #10 0x7fdfed7a4c47 in AppendImages MagickCore/image.c:533:10
    #11 0x7fdfecf6bd2d in CLIListOperatorImages MagickWand/operation.c:3795:22
    #12 0x7fdfecf7834e in CLIOption MagickWand/operation.c:5276:14
    #13 0x7fdfecdb9a99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
    #14 0x7fdfecdbad0a in MagickImageCommand MagickWand/magick-cli.c:796:5
    #15 0x7fdfece04ba1 in MagickCommandGenesis MagickWand/mogrify.c:185:14
    #16 0x526f95 in MagickMain utilities/magick.c:149:10
    #17 0x5268e1 in main utilities/magick.c:180:10
    #18 0x7fdfe787bb96 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 0x7fdfed7f4146 in AcquireMagickMemory MagickCore/memory.c:478:10
    #2 0x7fdfed7f41af in AcquireQuantumMemory MagickCore/memory.c:551:10
    #3 0x7fdfed7a6b3d in CloneImage MagickCore/image.c:879:43
    #4 0x7fdfed7a4a81 in AppendImages MagickCore/image.c:520:16
    #5 0x7fdfecf6bd2d in CLIListOperatorImages MagickWand/operation.c:3795:22
    #6 0x7fdfecf7834e in CLIOption MagickWand/operation.c:5276:14
    #7 0x7fdfecdb9a99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
    #8 0x7fdfecdbad0a in MagickImageCommand MagickWand/magick-cli.c:796:5
    #9 0x7fdfece04ba1 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 0x7fdfe787bb96 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 0x7fdfed7f4146 in AcquireMagickMemory MagickCore/memory.c:478:10
    #2 0x7fdfed7a1154 in AcquireCriticalMemory ./MagickCore/memory-private.h:64:10
    #3 0x7fdfed7a3793 in AcquireImageInfo MagickCore/image.c:350:28
    #4 0x7fdfed7ac553 in CloneImageInfo MagickCore/image.c:945:14
    #5 0x7fdfed7a36b8 in SyncImageSettings MagickCore/image.c:4242:21
    #6 0x7fdfed7baea6 in SyncImagesSettings MagickCore/image.c:4000:12
    #7 0x7fdfecf78153 in CLIOption MagickWand/operation.c:5243:14
    #8 0x7fdfecdb9a99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
    #9 0x7fdfecdbad0a in MagickImageCommand MagickWand/magick-cli.c:796:5
    #10 0x7fdfece04ba1 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 0x7fdfe787bb96 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 0x7fdfed7f3f66 in AcquireAlignedMemory MagickCore/memory.c:265:7
    #2 0x7fdfed526a04 in AcquirePixelCache MagickCore/cache.c:195:28
    #3 0x7fdfed527f8d in ClonePixelCache MagickCore/cache.c:513:28
    #4 0x7fdfed7a75df in CloneImage MagickCore/image.c:910:22
    #5 0x7fdfed7a4a81 in AppendImages MagickCore/image.c:520:16
    #6 0x7fdfecf6bd2d in CLIListOperatorImages MagickWand/operation.c:3795:22
    #7 0x7fdfecf7834e in CLIOption MagickWand/operation.c:5276:14
    #8 0x7fdfecdb9a99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
    #9 0x7fdfecdbad0a in MagickImageCommand MagickWand/magick-cli.c:796:5
    #10 0x7fdfece04ba1 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 0x7fdfe787bb96 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 0x7fdfed7f4146 in AcquireMagickMemory MagickCore/memory.c:478:10
    #2 0x7fdfed7f41af in AcquireQuantumMemory MagickCore/memory.c:551:10
    #3 0x7fdfed834f7a in AcquirePixelChannelMap MagickCore/pixel.c:101:35
    #4 0x7fdfed835154 in ClonePixelChannelMap MagickCore/pixel.c:139:13
    #5 0x7fdfed7a638f in CloneImage MagickCore/image.c:849:28
    #6 0x7fdfed7a4a81 in AppendImages MagickCore/image.c:520:16
    #7 0x7fdfecf6bd2d in CLIListOperatorImages MagickWand/operation.c:3795:22
    #8 0x7fdfecf7834e in CLIOption MagickWand/operation.c:5276:14
    #9 0x7fdfecdb9a99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
    #10 0x7fdfecdbad0a in MagickImageCommand MagickWand/magick-cli.c:796:5
    #11 0x7fdfece04ba1 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 0x7fdfe787bb96 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 0x7fdfed7f4146 in AcquireMagickMemory MagickCore/memory.c:478:10
    #2 0x7fdfed504284 in AcquireCriticalMemory ./MagickCore/memory-private.h:64:10
    #3 0x7fdfed505d5d in CloneBlobInfo MagickCore/blob.c:554:27
    #4 0x7fdfed7a6848 in CloneImage MagickCore/image.c:867:25
    #5 0x7fdfed7a4a81 in AppendImages MagickCore/image.c:520:16
    #6 0x7fdfecf6bd2d in CLIListOperatorImages MagickWand/operation.c:3795:22
    #7 0x7fdfecf7834e in CLIOption MagickWand/operation.c:5276:14
    #8 0x7fdfecdb9a99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
    #9 0x7fdfecdbad0a in MagickImageCommand MagickWand/magick-cli.c:796:5
    #10 0x7fdfece04ba1 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 0x7fdfe787bb96 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 0x7fdfed7f4146 in AcquireMagickMemory MagickCore/memory.c:478:10
    #2 0x7fdfed7f41af in AcquireQuantumMemory MagickCore/memory.c:551:10
    #3 0x7fdfed5275df in AcquirePixelCacheNexus MagickCore/cache.c:271:29
    #4 0x7fdfed526f8d in AcquirePixelCache MagickCore/cache.c:212:26
    #5 0x7fdfed527f8d in ClonePixelCache MagickCore/cache.c:513:28
    #6 0x7fdfed7a75df in CloneImage MagickCore/image.c:910:22
    #7 0x7fdfed7a4a81 in AppendImages MagickCore/image.c:520:16
    #8 0x7fdfecf6bd2d in CLIListOperatorImages MagickWand/operation.c:3795:22
    #9 0x7fdfecf7834e in CLIOption MagickWand/operation.c:5276:14
    #10 0x7fdfecdb9a99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
    #11 0x7fdfecdbad0a in MagickImageCommand MagickWand/magick-cli.c:796:5
    #12 0x7fdfece04ba1 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 0x7fdfe787bb96 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 0x7fdfed7f4146 in AcquireMagickMemory MagickCore/memory.c:478:10
    #2 0x7fdfed94f073 in AddValueToSplayTree MagickCore/splay-tree.c:189:21
    #3 0x7fdfed94ff7c in CloneSplayTree MagickCore/splay-tree.c:372:12
    #4 0x7fdfed884f23 in CloneImageProperties MagickCore/property.c:196:25
    #5 0x7fdfed7a5f99 in CloneImage MagickCore/image.c:839:10
    #6 0x7fdfed7a4a81 in AppendImages MagickCore/image.c:520:16
    #7 0x7fdfecf6bd2d in CLIListOperatorImages MagickWand/operation.c:3795:22
    #8 0x7fdfecf7834e in CLIOption MagickWand/operation.c:5276:14
    #9 0x7fdfecdb9a99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
    #10 0x7fdfecdbad0a in MagickImageCommand MagickWand/magick-cli.c:796:5
    #11 0x7fdfece04ba1 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 0x7fdfe787bb96 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 0x7fdfed7f4146 in AcquireMagickMemory MagickCore/memory.c:478:10
    #2 0x7fdfed9540c4 in AcquireCriticalMemory ./MagickCore/memory-private.h:64:10
    #3 0x7fdfed950155 in NewSplayTree MagickCore/splay-tree.c:1148:32
    #4 0x7fdfed94fd64 in CloneSplayTree MagickCore/splay-tree.c:360:14
    #5 0x7fdfed884f23 in CloneImageProperties MagickCore/property.c:196:25
    #6 0x7fdfed7a5f99 in CloneImage MagickCore/image.c:839:10
    #7 0x7fdfed7a4a81 in AppendImages MagickCore/image.c:520:16
    #8 0x7fdfecf6bd2d in CLIListOperatorImages MagickWand/operation.c:3795:22
    #9 0x7fdfecf7834e in CLIOption MagickWand/operation.c:5276:14
    #10 0x7fdfecdb9a99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
    #11 0x7fdfecdbad0a in MagickImageCommand MagickWand/magick-cli.c:796:5
    #12 0x7fdfece04ba1 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 0x7fdfe787bb96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)

Indirect leak of 80 byte(s) in 3 object(s) allocated from:
    #0 0x4e5397 in __interceptor_malloc (install/bin/magick+0x4e5397)
    #1 0x7fdfed7f4146 in AcquireMagickMemory MagickCore/memory.c:478:10
    #2 0x7fdfed7f41af in AcquireQuantumMemory MagickCore/memory.c:551:10
    #3 0x7fdfed987963 in ConstantString MagickCore/string.c:713:26
    #4 0x7fdfed94ff66 in CloneSplayTree MagickCore/splay-tree.c:373:7
    #5 0x7fdfed884f23 in CloneImageProperties MagickCore/property.c:196:25
    #6 0x7fdfed7a5f99 in CloneImage MagickCore/image.c:839:10
    #7 0x7fdfed7a4a81 in AppendImages MagickCore/image.c:520:16
    #8 0x7fdfecf6bd2d in CLIListOperatorImages MagickWand/operation.c:3795:22
    #9 0x7fdfecf7834e in CLIOption MagickWand/operation.c:5276:14
    #10 0x7fdfecdb9a99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
    #11 0x7fdfecdbad0a in MagickImageCommand MagickWand/magick-cli.c:796:5
    #12 0x7fdfece04ba1 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 0x7fdfe787bb96 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 0x7fdfed9397c1 in AcquireSemaphoreMemory MagickCore/semaphore.c:154:7
    #2 0x7fdfed939003 in AcquireSemaphoreInfo MagickCore/semaphore.c:200:36
    #3 0x7fdfed7a69df in CloneImage MagickCore/image.c:871:26
    #4 0x7fdfed7a4a81 in AppendImages MagickCore/image.c:520:16
    #5 0x7fdfecf6bd2d in CLIListOperatorImages MagickWand/operation.c:3795:22
    #6 0x7fdfecf7834e in CLIOption MagickWand/operation.c:5276:14
    #7 0x7fdfecdb9a99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
    #8 0x7fdfecdbad0a in MagickImageCommand MagickWand/magick-cli.c:796:5
    #9 0x7fdfece04ba1 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 0x7fdfe787bb96 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 0x7fdfed9397c1 in AcquireSemaphoreMemory MagickCore/semaphore.c:154:7
    #2 0x7fdfed939003 in AcquireSemaphoreInfo MagickCore/semaphore.c:200:36
    #3 0x7fdfed5061ae in GetBlobInfo MagickCore/blob.c:1745:24
    #4 0x7fdfed505d6a in CloneBlobInfo MagickCore/blob.c:555:3
    #5 0x7fdfed7a6848 in CloneImage MagickCore/image.c:867:25
    #6 0x7fdfed7a4a81 in AppendImages MagickCore/image.c:520:16
    #7 0x7fdfecf6bd2d in CLIListOperatorImages MagickWand/operation.c:3795:22
    #8 0x7fdfecf7834e in CLIOption MagickWand/operation.c:5276:14
    #9 0x7fdfecdb9a99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
    #10 0x7fdfecdbad0a in MagickImageCommand MagickWand/magick-cli.c:796:5
    #11 0x7fdfece04ba1 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 0x7fdfe787bb96 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 0x7fdfed9397c1 in AcquireSemaphoreMemory MagickCore/semaphore.c:154:7
    #2 0x7fdfed939003 in AcquireSemaphoreInfo MagickCore/semaphore.c:200:36
    #3 0x7fdfed527383 in AcquirePixelCache MagickCore/cache.c:231:30
    #4 0x7fdfed527f8d in ClonePixelCache MagickCore/cache.c:513:28
    #5 0x7fdfed7a75df in CloneImage MagickCore/image.c:910:22
    #6 0x7fdfed7a4a81 in AppendImages MagickCore/image.c:520:16
    #7 0x7fdfecf6bd2d in CLIListOperatorImages MagickWand/operation.c:3795:22
    #8 0x7fdfecf7834e in CLIOption MagickWand/operation.c:5276:14
    #9 0x7fdfecdb9a99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
    #10 0x7fdfecdbad0a in MagickImageCommand MagickWand/magick-cli.c:796:5
    #11 0x7fdfece04ba1 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 0x7fdfe787bb96 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 0x7fdfed9397c1 in AcquireSemaphoreMemory MagickCore/semaphore.c:154:7
    #2 0x7fdfed939003 in AcquireSemaphoreInfo MagickCore/semaphore.c:200:36
    #3 0x7fdfed5272f4 in AcquirePixelCache MagickCore/cache.c:229:25
    #4 0x7fdfed527f8d in ClonePixelCache MagickCore/cache.c:513:28
    #5 0x7fdfed7a75df in CloneImage MagickCore/image.c:910:22
    #6 0x7fdfed7a4a81 in AppendImages MagickCore/image.c:520:16
    #7 0x7fdfecf6bd2d in CLIListOperatorImages MagickWand/operation.c:3795:22
    #8 0x7fdfecf7834e in CLIOption MagickWand/operation.c:5276:14
    #9 0x7fdfecdb9a99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
    #10 0x7fdfecdbad0a in MagickImageCommand MagickWand/magick-cli.c:796:5
    #11 0x7fdfece04ba1 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 0x7fdfe787bb96 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 0x7fdfed7f3f66 in AcquireAlignedMemory MagickCore/memory.c:265:7
    #2 0x7fdfed5274e2 in AcquirePixelCacheNexus MagickCore/cache.c:267:29
    #3 0x7fdfed526f8d in AcquirePixelCache MagickCore/cache.c:212:26
    #4 0x7fdfed527f8d in ClonePixelCache MagickCore/cache.c:513:28
    #5 0x7fdfed7a75df in CloneImage MagickCore/image.c:910:22
    #6 0x7fdfed7a4a81 in AppendImages MagickCore/image.c:520:16
    #7 0x7fdfecf6bd2d in CLIListOperatorImages MagickWand/operation.c:3795:22
    #8 0x7fdfecf7834e in CLIOption MagickWand/operation.c:5276:14
    #9 0x7fdfecdb9a99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
    #10 0x7fdfecdbad0a in MagickImageCommand MagickWand/magick-cli.c:796:5
    #11 0x7fdfece04ba1 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 0x7fdfe787bb96 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 0x7fdfed9397c1 in AcquireSemaphoreMemory MagickCore/semaphore.c:154:7
    #2 0x7fdfed939003 in AcquireSemaphoreInfo MagickCore/semaphore.c:200:36
    #3 0x7fdfed9503c9 in NewSplayTree MagickCore/splay-tree.c:1159:25
    #4 0x7fdfed94fd64 in CloneSplayTree MagickCore/splay-tree.c:360:14
    #5 0x7fdfed884f23 in CloneImageProperties MagickCore/property.c:196:25
    #6 0x7fdfed7a5f99 in CloneImage MagickCore/image.c:839:10
    #7 0x7fdfed7a4a81 in AppendImages MagickCore/image.c:520:16
    #8 0x7fdfecf6bd2d in CLIListOperatorImages MagickWand/operation.c:3795:22
    #9 0x7fdfecf7834e in CLIOption MagickWand/operation.c:5276:14
    #10 0x7fdfecdb9a99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
    #11 0x7fdfecdbad0a in MagickImageCommand MagickWand/magick-cli.c:796:5
    #12 0x7fdfece04ba1 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 0x7fdfe787bb96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)

Indirect leak of 32 byte(s) in 3 object(s) allocated from:
    #0 0x4e5397 in __interceptor_malloc (install/bin/magick+0x4e5397)
    #1 0x7fdfed7f4146 in AcquireMagickMemory MagickCore/memory.c:478:10
    #2 0x7fdfed7f41af in AcquireQuantumMemory MagickCore/memory.c:551:10
    #3 0x7fdfed987963 in ConstantString MagickCore/string.c:713:26
    #4 0x7fdfed94fee1 in CloneSplayTree MagickCore/splay-tree.c:372:43
    #5 0x7fdfed884f23 in CloneImageProperties MagickCore/property.c:196:25
    #6 0x7fdfed7a5f99 in CloneImage MagickCore/image.c:839:10
    #7 0x7fdfed7a4a81 in AppendImages MagickCore/image.c:520:16
    #8 0x7fdfecf6bd2d in CLIListOperatorImages MagickWand/operation.c:3795:22
    #9 0x7fdfecf7834e in CLIOption MagickWand/operation.c:5276:14
    #10 0x7fdfecdb9a99 in ProcessCommandOptions MagickWand/magick-cli.c:477:7
    #11 0x7fdfecdbad0a in MagickImageCommand MagickWand/magick-cli.c:796:5
    #12 0x7fdfece04ba1 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 0x7fdfe787bb96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)

SUMMARY: AddressSanitizer: 1000000 byte(s) leaked in 24 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-18 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-18 19:20:19+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:48:39+00:00:
This was assigned CVE-2019-13296.

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

Additional files: