|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #73263 InvalidColormapIndex error not detectable
Submitted: 2016-10-07 10:52 UTC Modified: 2017-10-24 05:25 UTC
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: rainer-phpbugs at 7val dot com Assigned: danack (profile)
Status: Assigned Package: imagick (PECL)
PHP Version: 7.0.11 OS: Ubuntu 16.04 and others
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: rainer-phpbugs at 7val dot com
New email:
PHP Version: OS:


 [2016-10-07 10:52 UTC] rainer-phpbugs at 7val dot com
The "convert" program supplied with ImageMagick complains when converting the (defective) image located at with the message

convert: InvalidColormapIndex `/tmp/pages.gif' @ error/colormap-private.h/ConstrainColormapIndex/34.

and generates an output image without transparency. imagick also generates an output image without transparency, but, as far as I can tell, no error is flagged. 

Test script:

$imagick = new \Imagick();
if ($imagick->readImage($_SERVER['argv'][1])) {
} else {
    fprintf(STDERR, "error!\n");
    throw new Exception();

Expected result:
The error Message generated by libMagickWand/Core should be detectable and retrievable.

Actual result:
No detectable error (message) in imagick.

I have filed a bug report for this specific image's problem with imagemagick at however, any and all possible errors should be detectable.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2016-12-20 22:47 UTC]
-Status: Open +Status: Verified -Assigned To: +Assigned To: danack
 [2016-12-20 22:47 UTC]
I'm not sure it's going to be possible to do anything in PHP.

There is no error reported from the C api to ImageMagick with the test program below.

If there's no error reported, there's no steps we can take.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <malloc.h>
#include <wand/MagickWand.h>

int main(int argc,char **argv) {
    MagickWand *magick_wand;
    MagickBooleanType status;
    char *exception_text;
    ExceptionType severity;

    magick_wand = NewMagickWand();
    status = MagickReadImage(magick_wand, "./images/pages_invalid_gif.gif");

    if (status == MagickFalse) {
        printf("Failed to MagickReadImage");
        return -1;
    exception_text = MagickGetException(magick_wand, &severity);

    if (exception_text == NULL) {
        printf("exception_text is NULL\n");
    else {
        printf("exception_text is %s\n", exception_text);
    printf("Severity is %d\n", severity);

    MagickSetImageFormat(magick_wand, "png");

    status = MagickWriteImages(magick_wand, "./73263.png", MagickTrue);
    if (status == MagickFalse) {
        printf("Failed to MagickWriteImages");
        return -1;

 [2016-12-21 11:39 UTC] rainer-phpbugs at 7val dot com
With ImageMagick 6, I don't get any exception:

exception_text is 
Severity is 0

With ImageMagick 7 (currently 7.0.3-7) on the other hand, I get the exception below, but no errors from the PHP program I've posted above:

exception_text is InvalidColormapIndex `./pages.gif' @ error/colormap-private.h/ConstrainColormapIndex/34
Severity is 425
 [2016-12-21 16:25 UTC]
Ah, awesome. I didn't try it with IM7 - but if it is reporting that something is wrong, then we can do something about it.

I'll probably need to do this at at least a minor version, as it will probably 'break' 'working' code for some people, who are unaware that they are opening 'invalid' files.

Additionally, there is probably an argument for allowing the calling code to be able to continue past certain errors, which needs thinking about.

I've made a note about it here -
 [2016-12-21 17:10 UTC] rainer-phpbugs at 7val dot com
In this specific case, breaking working code may not be desirable, because imagick does load a somewhat acceptable representation of the file. The default behaviour should be to flag the error, but not to abort processing of the corrupt image.
 [2017-10-24 05:25 UTC]
-Status: Verified +Status: Assigned
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Wed Dec 06 15:01:27 2023 UTC