Page 1 of 1

Intermittent colormap error when using identify on PNGs

Posted: 2010-06-02T15:39:09-07:00
by moconnor
Hey guys. We're running into a problem with identify under ImageMagick 6.6.2-0 and 6.6.2-1, but not under 6.6.1-10. We're running on OS X.

On some PNG files the identify command will intermittently give an error. Here's the command we run:

Code: Select all

identify -format "%wx%h" path/to/image/file.png
Here's the error we sometimes get (about 39% of the time):

Code: Select all

identify: invalid colormap index <filename> @ error/image.c/SyncImage/3906
When the command fails with the above error the exit code is 1. I've uploaded a file which produces the error at http://i.imgur.com/L7d2p.png.

I ran 1000 trials and 607 times the command worked fine and 393 times the command failed.

We diffed the released code between 6.6.1-10 and 6.6.2-1. We noticed some changes from long to ssize_t that seemed suspicious (they occurred in the method getting the error), near line 3906 of image.c. I am not 100% sure that's the problem, just noticed it while hunting around for a probable cause. Here's the relevant diff portion I am referring to:

Code: Select all

@@ -3865,7 +3871,7 @@
     register IndexPacket
       *restrict indexes;
 
-    register long
+    register ssize_t
       x;
 
     register PixelPacket
@@ -3880,11 +3886,11 @@
         continue;
       }
     indexes=GetCacheViewAuthenticIndexQueue(image_view);
-    for (x=0; x < (long) image->columns; x++)
+    for (x=0; x < (ssize_t) image->columns; x++)
     {
-      index=PushColormapIndex(image,(unsigned long) indexes[x],
+      index=PushColormapIndex(image,(size_t) indexes[x],
         &range_exception);
-      pixel=image->colormap[(long) index];
+      pixel=image->colormap[(ssize_t) index];
       q->red=pixel.red;
       q->green=pixel.green;
       q->blue=pixel.blue;
We noticed in the ChangeLog that a similar bug was fixed on May 8th. I am not sure if this represents a regression or not:

Code: Select all

2010-05-08  6.6.1-7 Cristy  <quetzlzacatenango@image...>
  * Fix improper 'invalid colormap index' PNG bug.
Below is all of my possibly relevant system information I could think of:

Versions Tried
6.6.1-10: bug not present
6.6.2-0: buggy
6.6.2-1: buggy

System Specifications
Model: 27" iMac (iMac11,1)
OS: Mac OS X 10.6.3
Processor: 2.8 GHz Intel Core i7 (4 cores)
Memory: 4GB 1067 MHz DDR3

Code: Select all

$ uname -a
Darwin turkleton.local 10.3.0 Darwin Kernel Version 10.3.0: Fri Feb 26 11:58:09 PST 2010; root:xnu-1504.3.12~1/RELEASE_I386 i386

Code: Select all

$ brew info imagemagick
imagemagick 6.6.2-1

Code: Select all

$ file $(which identify)
/usr/local/bin/identify: Mach-O 64-bit executable x86_64

Code: Select all

$ identify --version
Version: ImageMagick 6.6.2-1 2010-06-02 Q16 http://www.imagemagick.org
Options Given to ./configure

Code: Select all

./configure --disable-osx-universal-binary --without-perl --prefix=/usr/local/Cellar/imagemagick/6.6.2-1 --disable-dependency-tracking --enable-shared --disable-static --with-modules --without-magick-plus-plus --without-gslib --with-gs-font-dir=/usr/local/share/ghostscript/fonts
We printed out the native sizes of long, Int, and ssize_t on our system:

Code: Select all

Long: 8
Int: 4
ssize_t: 8
The program we used to compute the type sizes is as follows:

Code: Select all

/*
 *
 * $ gcc -Wall -O0 sizes.c -o sizes
 * $ ./sizes
 * Long: 8
 * Int: 4
 * ssize_t: 8
 * 
 */
#include <stdio.h>
#include <unistd.h>

int main() {
  printf("Long: %lu\n", sizeof(long));
  printf("Int: %lu\n", sizeof(int));
  printf("ssize_t: %lu\n", sizeof(ssize_t));
  return 0;
}

Re: Intermittent colormap error when using identify on PNGs

Posted: 2010-06-07T20:50:14-07:00
by fmw42
On some PNG files the identify command will intermittently give an error. Here's the command we run:

CODE: SELECT ALL
identify -format "%wx%h" path/to/image/file.png

Here's the error we sometimes get (about 39% of the time):
IM 6.6.2.3 Q16 HDRI Mac OSX Tiger:

I ran this loop and it correctly identified the size as 100x100 100% of the time.

for ((i=0; i<100; i++)); do
id=`identify -format "%wx%h" L7d2p.png`
echo "$i $id"
done

Re: Intermittent colormap error when using identify on PNGs

Posted: 2010-06-10T13:57:55-07:00
by shwoodard
I am getting the same thing, but it is happening about every other time I run the command.

Re: Intermittent colormap error when using identify on PNGs

Posted: 2010-06-10T15:05:29-07:00
by fmw42
shwoodard wrote:I am getting the same thing, but it is happening about every other time I run the command.
On what IM release and what platform?

I just re-ran the loop above on IM 6.6.2-4 Q16 (non-HDRI) Mac OSX Tiger and it ran successfully for every one of the 100 iterations.

Re: Intermittent colormap error when using identify on PNGs

Posted: 2010-06-10T15:57:46-07:00
by snibgo
No problems in Windows 7, IM 6.6.2-4 Q16 (64 bit):

Code: Select all

for /L %i in (1,1,100) do identify -format "%wx%h" L7d2p.png
(Edit: corrected typo in command line.)

Re: Intermittent colormap error when using identify on PNGs

Posted: 2010-06-10T18:01:18-07:00
by adamv
The sample image above is working for me with 6.6.2-4 compiled via Homebrew.

My system is: dual-core 64-bit core2, OS X: 10.6.3

We got a bug report on this issue, though http://github.com/mxcl/homebrew/issues/issue/1573 and I'm trying to get the reporter to give some system info.

Re: Intermittent colormap error when using identify on PNGs

Posted: 2010-06-10T18:49:43-07:00
by shwoodard
I fixed this by removing the Imagemagick that I had installed with homebrew and installing it again using http://github.com/masterkain/ImageMagick-sl.

Re: Intermittent colormap error when using identify on PNGs

Posted: 2010-06-10T21:19:46-07:00
by shwoodard
Scratch that...still broken. Now, if I do /usr/local/bin/identify foo, it works. But, if i just do identify foo, it does not work. In other words, if I supply the fully path to identify the command works, otherwise, the following error occurs,

$ identify -format %wx%h /var/folders/It/ItkZOuw-Ef8DhALMx76IPU+++TI/-Tmp-/stream18638-1,18638,0
identify: invalid colormap index `/var/folders/It/ItkZOuw-Ef8DhALMx76IPU+++TI/-Tmp-/stream18638-1,18638,0' @ error/image.c/SyncImage/3894.
5x5

Re: Intermittent colormap error when using identify on PNGs

Posted: 2010-06-10T21:26:26-07:00
by fmw42
sounds like an IM confusion. do you have more than one IM installed (perhaps in more than one place, e.g /usr/local/bin and /usr/bin or somewhere else). possibly they are getting confused and when you do identify without the full path it is going to one version that is not properly installed or cannot find the files it needs.

P.S. This appears to be a different issue than the original post. It is usually not good to tack onto another post. For best results in getting this resolved or the attention of the IM staff, I would suggest you repost as a new topic.

Re: Intermittent colormap error when using identify on PNGs

Posted: 2010-06-11T09:43:50-07:00
by shwoodard
Unfortunately, this is not the case: I have only one version of IM installed. I did use http://github.com/masterkain/ImageMagick-sl a second time and change it to use 6.6.1-10, as recommended above. Everything seems to be working fine now.

Re: Intermittent colormap error when using identify on PNGs

Posted: 2010-06-14T14:18:23-07:00
by shwoodard
Sorry to say it's working and then it's not and then it is... However, it seems that the solution described above fails as well. Interestingly,

OK (full path):

$ /usr/local/bin/identify -format %wx%h /var/folders/It/ItkZOuw-Ef8DhALMx76IPU+++TI/-Tmp-/stream470-2,470,1 5x5

FAIL:

$ identify -format %wx%h /var/folders/It/ItkZOuw-Ef8DhALMx76IPU+++TI/-Tmp-/stream470-2,470,1 identify: invalid colormap index `/var/folders/It/ItkZOuw-Ef8DhALMx76IPU+++TI/-Tmp-/stream470-2,470,1' @ error/image.c/SyncImage/3900.
5x5

Before you ask:

$ which identify /usr/local/bin/identify

I have:

Macbook Pro i5

Re: Intermittent colormap error when using identify on PNGs

Posted: 2010-06-14T14:24:25-07:00
by moconnor
The latest version of Imagemagick seems to work great (version: 6.6.2-4). The problem has disappeared for me.

Re: Intermittent colormap error when using identify on PNGs

Posted: 2013-07-10T01:24:20-07:00
by maclab
Hello,

I have found similar issue related to the simple BMP image, example:

Code: Select all


$ uname -a
Linux cocojambo 3.5.0-27-generic #46~precise1-Ubuntu SMP Tue Mar 26 19:33:21 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux

$ echo \
    Qk2SAAAAAAAAAD4AAAAoAAAAEQAAABUAAAABAAEAAAAAAFQAAAASCwAAEgsAAAIAAAACAAAAAAAA \
    AP///wD4D4AA4AOAAMABgACD4IAAh/AAAAf4AAAP+AAA//AAAP/AgAD8AIAA4AOAAMAHgACAf4AA \
    A/+AAA//gAAP8IAAD+CAAIPBgACAAYAAwAeAAPgPgAA= \
  | sed "s,\s,,g" | base64 -d > image.bmp

$ identify --version
Version: ImageMagick 6.6.9-7 2012-08-17 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2011 ImageMagick Studio LLC
Features: OpenMP

$ identify image.bmp
image.bmp BMP 17x21 17x21+0+0 1-bit PseudoClass 2c 146B 0.020u 0:00.000
$ identify image.bmp
image.bmp BMP 17x21 17x21+0+0 1-bit PseudoClass 2c 146B 0.000u 0:00.000
$ identify image.bmp
image.bmp BMP 17x21 17x21+0+0 1-bit PseudoClass 2c 146B 0.000u 0:00.000
$ identify image.bmp
image.bmp BMP 17x21 17x21+0+0 1-bit PseudoClass 2c 146B 0.030u 0:00.010
identify: invalid colormap index `image.bmp' @ error/image.c/SyncImage/4317.
$ identify image.bmp
image.bmp BMP 17x21 17x21+0+0 1-bit PseudoClass 2c 146B 0.020u 0:00.010
identify: invalid colormap index `image.bmp' @ error/image.c/SyncImage/4317.
$ identify image.bmp
image.bmp BMP 17x21 17x21+0+0 1-bit PseudoClass 2c 146B 0.000u 0:00.000
Regards

Re: Intermittent colormap error when using identify on PNGs

Posted: 2013-07-10T08:17:42-07:00
by glennrp
I'm not seeing this incorrect BMP behavior with IM-6.8.6-4 on Ubuntu. I ran "identify" a couple of thousand times.