BUG: WriteOnePNGImage() opaque array is too small

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
reblom
Posts: 3
Joined: 2011-01-25T05:23:41-07:00
Authentication code: 8675308

BUG: WriteOnePNGImage() opaque array is too small

Post by reblom »

When compiling and testing the imagemagick library under windows, I encountered the following error:
in the WriteOnePNGImage() function, an array opaque is defined:

Code: Select all

 PixelPacket opaque[260]
The array consists of 260 elements, but up to 300 elements (indices 0 - 299) may be accessed and set by the code.

Under windows, in the debug version of convert.exe, this causes an assertion failure warning about the stack that has been corrupted around the opaque variable:
"Run-Time Check Failure #2 - Stack around the variable 'opaque' was corrupted."

Under *nix variants, the bug probably exists as well, but might not manifest itself.

imagemagick source: 6.6.7
windows version: windows xp, sp3 (5.1, build 2600)
visual studio version: 2008

affected code, all in coders/png.c:

Code: Select all

// definition:
     PixelPacket  // line 7008-7010
    ...
       opaque[260],

Code: Select all

// usage of the opaque variable: number_opaque can have a maximum value of 299, which causes the code to set values outside of the opaque array.
 if (colormap[i].opacity == OpaqueOpacity) // line 7142-7143
    opaque[number_opaque++] = colormap[i];
Other defined variables might be affected in the same way, but I did not test that:

Code: Select all

     PixelPacket // line 7008-7012
       semitransparent[260],
       transparent[260];
With kind regards,
Roland
reblom
Posts: 3
Joined: 2011-01-25T05:23:41-07:00
Authentication code: 8675308

Re: BUG: WriteOnePNGImage() opaque array is too small

Post by reblom »

I forgot to mention:

I encountered the bug using the following commandline:
convert.exe -resize 100x100 d:\amsterdam.jpg d:\amsterdam.png

Where amsterdam.jpg is the image downloaded from here:
http://news.cheapflights.com/wp-content ... terdam.jpg

Greetings,
Roland
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: BUG: WriteOnePNGImage() opaque array is too small

Post by glennrp »

I believe I fixed that in 6.6.7-2.

Glenn
reblom
Posts: 3
Joined: 2011-01-25T05:23:41-07:00
Authentication code: 8675308

Re: BUG: WriteOnePNGImage() opaque array is too small

Post by reblom »

I downloaded version 6.6.7-2 (previously I used imagemagick-windows.zip, which is based on 6.6.7), and it is indeed fixed there.
Thank you!

Greetings,
Roland
Post Reply