php.net |  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
Votes:1
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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: rainer-phpbugs at 7val dot com
New email:
PHP Version: OS:

 

 [2016-10-07 10:52 UTC] rainer-phpbugs at 7val dot com
Description:
------------
The "convert" program supplied with ImageMagick complains when converting the (defective) image located at http://canavan.de/imbugs/pages.gif 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:
---------------
<?php

$imagick = new \Imagick();
if ($imagick->readImage($_SERVER['argv'][1])) {
    print($imagick->getImageBlob());
} 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 
http://www.imagemagick.org/discourse-server/viewtopic.php?f=3&t=30608 however, any and all possible errors should be detectable.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-12-20 22:47 UTC] danack@php.net
-Status: Open +Status: Verified -Assigned To: +Assigned To: danack
 [2016-12-20 22:47 UTC] danack@php.net
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;

    MagickWandGenesis();
    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;
    }

    MagickWandTerminus();
 
    return(0);
}
 [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] danack@php.net
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 - https://github.com/mkoppanen/imagick/issues/164
 [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] kalle@php.net
-Status: Verified +Status: Assigned
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Nov 22 04:01:28 2024 UTC