Menu

#557 ErrorCorruptImage: Magick: Unexpected end-of-file () for some ico images

v1.0_(example)
closed-fixed
None
5
2018-05-01
2018-04-12
No

The Magick::Image constructor fails for some ICO files with the error:

ErrorCorruptImage: Magick: Unexpected end-of-file () reported by coders/dib.c:1002 (ReadDIBImage)

This is the code snippet:

Magick::InitializeMagick(NULL);
...
Magick::Image image(icoImage.c_str());
image.magick("PNG");
image.write(pngImage.str().c_str());
...

The file with source code is attached.
I use Debian 9 with libgraphicsmagick library

libgraphicsmagick++-q16-12 1.3.25-8
libgraphicsmagick++1-dev 1.3.25-8
libgraphicsmagick-q16-3 1.3.25-8
libgraphicsmagick1-dev 1.3.25-8

To build attached source file on Debian 9 run:
g++ -Wall -I/usr/include/GraphicsMagick/ -o convert-ico-to-png convert-ico-to-png.cpp -lGraphicsMagick++

There are 3 attached ICO files:
favicon-image-1.ico
favicon-image-2.ico
favicon-image-3.ico

The Image constructor fails on loading favicon-image-1.ico but reads and converts successfully 2 other images to PNG

$ identify favicon-image-1.ico
favicon-image-1.ico[0] ICO 64x64 64x64+0+0 32-bit sRGB 33KB 0.000u 0:00.000
favicon-image-1.ico[1] ICO 32x32 32x32+0+0 32-bit sRGB 33KB 0.000u 0:00.000
favicon-image-1.ico[2] ICO 24x24 24x24+0+0 32-bit sRGB 33KB 0.000u 0:00.000
favicon-image-1.ico[3] ICO 16x16 16x16+0+0 32-bit sRGB 33KB 0.000u 0:00.000

$ identify favicon-image-2.ico
favicon-image-2.ico[0] ICO 16x16 16x16+0+0 32-bit sRGB 5.43KB 0.000u 0:00.000
favicon-image-2.ico[1] ICO 32x32 32x32+0+0 32-bit sRGB 5.43KB 0.000u 0:00.000

$ identify favicon-image-3.ico
favicon-image-3.ico[0] ICO 128x128 128x128+0+0 4-bit sRGB 17.2KB 0.000u 0:00.000
favicon-image-3.ico[1] ICO 72x72 72x72+0+0 4-bit sRGB 17.2KB 0.000u 0:00.000
favicon-image-3.ico[2] ICO 48x48 48x48+0+0 4-bit sRGB 17.2KB 0.000u 0:00.000
favicon-image-3.ico[3] ICO 32x32 32x32+0+0 4-bit sRGB 17.2KB 0.000u 0:00.000
favicon-image-3.ico[4] ICO 24x24 24x24+0+0 4-bit sRGB 17.2KB 0.000u 0:00.000
favicon-image-3.ico[5] ICO 16x16 16x16+0+0 4-bit sRGB 17.2KB 0.000u 0:00.000

4 Attachments

Discussion

  • Valentine Rozental

    The same code works for all attached ICO images on Debian 7 with 1.3.16 libraries:

    libgraphicsmagick++1-dev 1.3.16-1.1
    libgraphicsmagick++3 1.3.16-1.1
    libgraphicsmagick1-dev 1.3.16-1.1
    libgraphicsmagick3 1.3.16-1.1

    The favicon-image-1.ico is converted to PNG, but the quality is not good.

     
  • Valentine Rozental

    Has anyone run into the same problem?

     
    • Bob Friesenhahn

      Bob Friesenhahn - 2018-04-16

      On Mon, 16 Apr 2018, valentine wrote:

      Has anyone run into the same problem?

      I have not had time yet to investigate this further. Due to ongoing
      "security" updates, readers are on a "hair trigger" such that any
      error detected while reading the image data (even just one byte) will
      result in an error report rather than returning a partially corrupt
      image. If the file is even one byte short (according to the decoder)
      there will be an error report.

      Bob

       
  • Valentine Rozental

    Hi Bob,
    thank you for the answer!
    Meantime I tried different approach by extracting image binary data from the original ICO file and trying to construct an image using the constructor with Blob - the result was the same:
    ErrorCorruptImage: Magick: Unexpected end-of-file () reported by coders/dib.c:1002 (ReadDIBImage)

    Please let me know if you need more examples of ICO files that cause to the problem.
    Thank you!
    Valentine.

     
    • Bob Friesenhahn

      Bob Friesenhahn - 2018-04-16

      On Mon, 16 Apr 2018, valentine wrote:

      Please let me know if you need more examples of ICO files that cause to the problem.
      Thank you!

      Examples are always welcome. It is wise to bundle up files into a zip
      file and upload the zip file because SourceForge will re-write formats
      that it recognizes, losing the original issue.

      Bob

       
  • Bob Friesenhahn

    Bob Friesenhahn - 2018-04-28
    • status: open --> closed-fixed
    • assigned_to: Bob Friesenhahn
     
  • Bob Friesenhahn

    Bob Friesenhahn - 2018-04-28

    While is perhaps not the best solution, Mercurial changeset 15606:6b2168007560 eliminates the error report. The problem is that it was expected that there be a mask image following the DIB data but there was nothing after the DIB data. Improvements to this is a task for the future.

     
  • Valentine Rozental

    Thank you very much Bob!

     
  • Valentine Rozental

    What version of the GraphicsMagick library will contain the solution?

     
    • Bob Friesenhahn

      Bob Friesenhahn - 2018-05-01

      On Tue, 1 May 2018, Valentine Rozental wrote:

      What version of the GraphicsMagick library will contain the solution?

      The 1.3.29 release (made on April 29) contains the solution.

      Bob

       

Log in to post a comment.

MongoDB Logo MongoDB