ImageMagick 7.0.8-50 Q16 has a stack-based buffer overflow at coders/pnm.c in WritePNMImage because of a misplaced assignment.
cpe:2.3:a:imagemagick:imagemagick:7.0.8-50:q16:*:*:*:*:*:*
25CCEA99-8329-46C6-9625-4FE15F24CF69
OR
cpe:2.3:o:debian:debian_linux:8.0:*:*:*:*:*:*:*
C11E6FB0-C8C0-4527-9AA0-CB9B316F8F43
cpe:2.3:o:debian:debian_linux:9.0:*:*:*:*:*:*:*
DEECE5FC-CACF-4496-A3E7-164736409252
cpe:2.3:o:debian:debian_linux:10.0:*:*:*:*:*:*:*
07B237A9-69A3-4A9C-9DA0-4E06BD37AE73
OR
cpe:2.3:o:canonical:ubuntu_linux:16.04:*:*:*:esm:*:*:*
7A5301BF-1402-4BE0-A0F8-69FBE79BC6D6
cpe:2.3:o:canonical:ubuntu_linux:18.04:*:*:*:lts:*:*:*
23A7C53F-B80F-4E6A-AFA9-58EEA84BE11D
cpe:2.3:o:canonical:ubuntu_linux:19.04:*:*:*:*:*:*:*
CD783B0C-9246-47D9-A937-6144FE8BFF0F
cpe:2.3:o:canonical:ubuntu_linux:19.10:*:*:*:*:*:*:*
A31C8344-3E02-4EB8-8BD8-4C84B7959624
OR
cpe:2.3:o:opensuse:leap:15.0:*:*:*:*:*:*:*
F1E78106-58E6-4D59-990F-75DA575BFAD9
cpe:2.3:o:opensuse:leap:15.1:*:*:*:*:*:*:*
B620311B-34A3-48A6-82DF-6F078D7A4493
OR
### 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 a stack buffer overflow at coders/pnm.c:1762 in WritePNMImage.

### 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 -render "(" magick:rose -sample 846x913^+16+22 -white-threshold 112  ")" -compress None -adjoin  tmp`

Here's ASAN log.
```
=================================================================
==9828==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7ffcc293daa0 at pc 0x7f71ad7e3477 bp 0x7ffcc293a0f0 sp 0x7ffcc293a0e8
WRITE of size 1 at 0x7ffcc293daa0 thread T0
    #0 0x7f71ad7e3476 in WritePNMImage coders/pnm.c:1762:21
    #1 0x7f71ad07c065 in WriteImage MagickCore/constitute.c:1159:16
    #2 0x7f71ad07cf8c in WriteImages MagickCore/constitute.c:1376:13
    #3 0x7f71aca4050d in CLINoImageOperator MagickWand/operation.c:4796:14
    #4 0x7f71aca441cc in CLIOption MagickWand/operation.c:5258:7
    #5 0x7f71ac885f6d in ProcessCommandOptions MagickWand/magick-cli.c:529:3
    #6 0x7f71ac886d0a in MagickImageCommand MagickWand/magick-cli.c:796:5
    #7 0x7f71ac8d0ba1 in MagickCommandGenesis MagickWand/mogrify.c:185:14
    #8 0x526f95 in MagickMain utilities/magick.c:149:10
    #9 0x5268e1 in main utilities/magick.c:180:10
    #10 0x7f71a7347b96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
    #11 0x41b069 in _start (install/bin/magick+0x41b069)

Address 0x7ffcc293daa0 is located in stack of thread T0 at offset 14752 in frame
    #0 0x7f71ad7e1daf in WritePNMImage coders/pnm.c:1522

  This frame has 6 object(s):
    [32, 4128) 'buffer' (line 1523)
    [4256, 8352) 'magick' (line 1523)
    [8480, 12576) 'type117' (line 1675)
    [12704, 14752) 'pixels' (line 1736) <== Memory access at offset 14752 overflows this variable
    [14880, 16928) 'pixels255' (line 1788)
    [17056, 19104) 'pixels381' (line 1857)
HINT: this may be a false positive if your program uses some custom stack unwind mechanism, swapcontext or vfork
      (longjmp and C++ exceptions *are* supported)
SUMMARY: AddressSanitizer: stack-buffer-overflow coders/pnm.c:1762:21 in WritePNMImage

```

### 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-21 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! -->

stack-buffer-overflow at coders/pnm.c:1762 in WritePNMImage
This is a GitHub Issue
repo:ImageMagick
owner:ImageMagick
Title : stack-buffer-overflow at coders/pnm.c:1762 in WritePNMImage
Issue date:

--- start 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 a stack buffer overflow at coders/pnm.c:1762 in WritePNMImage.

### 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 -render "(" magick:rose -sample 846x913^+16+22 -white-threshold 112  ")" -compress None -adjoin  tmp`

Here's ASAN log.
```
=================================================================
==9828==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7ffcc293daa0 at pc 0x7f71ad7e3477 bp 0x7ffcc293a0f0 sp 0x7ffcc293a0e8
WRITE of size 1 at 0x7ffcc293daa0 thread T0
    #0 0x7f71ad7e3476 in WritePNMImage coders/pnm.c:1762:21
    #1 0x7f71ad07c065 in WriteImage MagickCore/constitute.c:1159:16
    #2 0x7f71ad07cf8c in WriteImages MagickCore/constitute.c:1376:13
    #3 0x7f71aca4050d in CLINoImageOperator MagickWand/operation.c:4796:14
    #4 0x7f71aca441cc in CLIOption MagickWand/operation.c:5258:7
    #5 0x7f71ac885f6d in ProcessCommandOptions MagickWand/magick-cli.c:529:3
    #6 0x7f71ac886d0a in MagickImageCommand MagickWand/magick-cli.c:796:5
    #7 0x7f71ac8d0ba1 in MagickCommandGenesis MagickWand/mogrify.c:185:14
    #8 0x526f95 in MagickMain utilities/magick.c:149:10
    #9 0x5268e1 in main utilities/magick.c:180:10
    #10 0x7f71a7347b96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
    #11 0x41b069 in _start (install/bin/magick+0x41b069)

Address 0x7ffcc293daa0 is located in stack of thread T0 at offset 14752 in frame
    #0 0x7f71ad7e1daf in WritePNMImage coders/pnm.c:1522

  This frame has 6 object(s):
    [32, 4128) 'buffer' (line 1523)
    [4256, 8352) 'magick' (line 1523)
    [8480, 12576) 'type117' (line 1675)
    [12704, 14752) 'pixels' (line 1736) <== Memory access at offset 14752 overflows this variable
    [14880, 16928) 'pixels255' (line 1788)
    [17056, 19104) 'pixels381' (line 1857)
HINT: this may be a false positive if your program uses some custom stack unwind mechanism, swapcontext or vfork
      (longjmp and C++ exceptions *are* supported)
SUMMARY: AddressSanitizer: stack-buffer-overflow coders/pnm.c:1762:21 in WritePNMImage

```

### 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-21 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! -->

--- end body ---

comments :
--- start comments ---

--- end comments ---