Page 1 of 1

"Invalid chunk type" when converting .ico to .png

Posted: 2011-10-02T03:44:18-07:00
by mls39
For certain .ico files the simple command:

convert CAD_AAA.ico CAD_AAA.png

either crashes imagemagick or returns the error:

Magick: [01][00][20][00]: invalid chunk type `CAD_AAA.ico' @ error/png.c/MagickP
NGErrorHandler/1728.
Magick: corrupt image `CAD_AAA.ico' @ error/png.c/ReadPNGImage/3695.

All the icons i am having problems with open without problems in any other graphics program, eg.paint, gimp, greenfish. Saving the icon (unedited) using any of these also fixes the problem.

Perhaps it's a minor corruption of the ico files or a slightly different format that IM doesn't handle.

I'm using ImageMagick-6.7.2-9

Here's the ouput of the same command run with debug All:

Would like to attach the icon but as this is my first post, I don't know how to do it yet.

Code: Select all

C:\Program Files\TrueLaunchBar\skins\Metro\Icons\tmp>convert -debug All CAD_AAA.
ico CAD_AAA.png > 1.log
2011-10-02T21:33:09+11:00 0:00.003 0.000u 6.7.2 Configure Magick[2932]: utility.
c/ExpandFilenames/907/Configure
  Command line: convert {-debug} {All} {CAD_AAA.ico} {CAD_AAA.png}
2011-10-02T21:33:09+11:00 0:00.008 0.000u 6.7.2 Configure Magick[2932]: nt-base.
c/NTRegistryKeyLookup/1661/Configure
  SOFTWARE\ImageMagick\6.7.2\Q:16
2011-10-02T21:33:09+11:00 0:00.014 0.016u 6.7.2 Configure Magick[2932]: nt-base.
c/NTRegistryKeyLookup/1679/Configure
  ConfigurePath
2011-10-02T21:33:09+11:00 0:00.022 0.016u 6.7.2 Configure Magick[2932]: configur
e.c/GetConfigureOptions/564/Configure
  Searching for configure file: "C:\Program Files\ImageMagick-6.7.2-Q16\coder.xm
l"
2011-10-02T21:33:09+11:00 0:00.033 0.031u 6.7.2 Configure Magick[2932]: configur
e.c/GetConfigureOptions/564/Configure
  Searching for configure file: "C:\Users\Paul\.magick\coder.xml"
2011-10-02T21:33:09+11:00 0:00.038 0.031u 6.7.2 Configure Magick[2932]: configur
e.c/GetConfigureOptions/564/Configure
  Searching for configure file: "C:\Program Files\ImageMagick-6.7.2-Q16\coder.xm
l"
2011-10-02T21:33:09+11:00 0:00.046 0.031u 6.7.2 Configure Magick[2932]: coder.c/
LoadCoderList/690/Configure
  Loading coder configuration file "C:\Program Files\ImageMagick-6.7.2-Q16\coder
.xml" ...
2011-10-02T21:33:09+11:00 0:00.052 0.031u 6.7.2 Configure Magick[2932]: coder.c/
LoadCoderList/690/Configure
  Loading coder configuration file "C:\Program Files\ImageMagick-6.7.2-Q16\coder
.xml" ...
2011-10-02T21:33:09+11:00 0:00.057 0.047u 6.7.2 Configure Magick[2932]: coder.c/
LoadCoderList/690/Configure
  Loading coder configuration file "coder.xml" ...
2011-10-02T21:33:09+11:00 0:00.065 0.047u 6.7.2 Module Magick[2932]: module.c/Op
enModule/1264/Module
  Searching for module "ICON" using filename "IM_MOD_RL_ICON_.dll"
2011-10-02T21:33:09+11:00 0:00.070 0.047u 6.7.2 Module Magick[2932]: module.c/Ge
tMagickModulePath/565/Module
  Searching for coder module file "IM_MOD_RL_ICON_.dll" ...
2011-10-02T21:33:09+11:00 0:00.074 0.047u 6.7.2 Configure Magick[2932]: nt-base.
c/NTRegistryKeyLookup/1661/Configure
  SOFTWARE\ImageMagick\6.7.2\Q:16
2011-10-02T21:33:09+11:00 0:00.084 0.047u 6.7.2 Configure Magick[2932]: nt-base.
c/NTRegistryKeyLookup/1679/Configure
  CoderModulesPath
2011-10-02T21:33:09+11:00 0:00.088 0.062u 6.7.2 Module Magick[2932]: module.c/Op
enModule/1273/Module
  Opening module at path "C:\Program Files\ImageMagick-6.7.2-Q16\modules\coders\
IM_MOD_RL_ICON_.dll"
2011-10-02T21:33:09+11:00 0:00.097 0.062u 6.7.2 Module Magick[2932]: module.c/Op
enModule/1300/Module
  Method "RegisterICONImage" in module "ICON" at address 6F8331C0
2011-10-02T21:33:09+11:00 0:00.101 0.062u 6.7.2 Module Magick[2932]: module.c/Op
enModule/1314/Module
  Method "UnregisterICONImage" in module "ICON" at address 6F8322B0
2011-10-02T21:33:09+11:00 0:00.106 0.062u 6.7.2 Policy Magick[2932]: policy.c/Is
RightsAuthorized/485/Policy
  Domain: Path; rights=Read; pattern="CAD_AAA.ico" ...
2011-10-02T21:33:09+11:00 0:00.113 0.062u 6.7.2 Blob Magick[2932]: blob.c/OpenBl
ob/2482/Blob
    read 3 magic header bytes
2011-10-02T21:33:09+11:00 0:00.116 0.062u 6.7.2 Cache Magick[2932]: cache.c/Dest
royPixelCache/1505/Cache
  destroy
2011-10-02T21:33:09+11:00 0:00.121 0.078u 6.7.2 Configure Magick[2932]: nt-base.
c/NTRegistryKeyLookup/1661/Configure
  SOFTWARE\ImageMagick\6.7.2\Q:16
2011-10-02T21:33:09+11:00 0:00.125 0.078u 6.7.2 Configure Magick[2932]: nt-base.
c/NTRegistryKeyLookup/1679/Configure
  ConfigurePath
2011-10-02T21:33:09+11:00 0:00.131 0.078u 6.7.2 Configure Magick[2932]: configur
e.c/GetConfigureOptions/564/Configure
  Searching for configure file: "C:\Program Files\ImageMagick-6.7.2-Q16\magic.xm
l"
2011-10-02T21:33:09+11:00 0:00.136 0.078u 6.7.2 Configure Magick[2932]: configur
e.c/GetConfigureOptions/564/Configure
  Searching for configure file: "C:\Users\Paul\.magick\magic.xml"
2011-10-02T21:33:09+11:00 0:00.141 0.078u 6.7.2 Configure Magick[2932]: configur
e.c/GetConfigureOptions/564/Configure
  Searching for configure file: "C:\Program Files\ImageMagick-6.7.2-Q16\magic.xm
l"
2011-10-02T21:33:09+11:00 0:00.149 0.078u 6.7.2 Configure Magick[2932]: magic.c/
LoadMagicList/679/Configure
  Loading magic configure file "C:\Program Files\ImageMagick-6.7.2-Q16\magic.xml
" ...
2011-10-02T21:33:09+11:00 0:00.155 0.078u 6.7.2 Configure Magick[2932]: magic.c/
LoadMagicList/679/Configure
  Loading magic configure file "C:\Program Files\ImageMagick-6.7.2-Q16\magic.xml
" ...
2011-10-02T21:33:09+11:00 0:00.161 0.078u 6.7.2 Configure Magick[2932]: magic.c/
LoadMagicList/679/Configure
  Loading magic configure file "magic.xml" ...
2011-10-02T21:33:09+11:00 0:00.167 0.078u 6.7.2 Policy Magick[2932]: policy.c/Is
RightsAuthorized/485/Policy
  Domain: Coder; rights=Read; pattern="ICO" ...
2011-10-02T21:33:09+11:00 0:00.171 0.078u 6.7.2 Policy Magick[2932]: policy.c/Is
RightsAuthorized/485/Policy
  Domain: Path; rights=Read; pattern="CAD_AAA.ico" ...
2011-10-02T21:33:09+11:00 0:00.176 0.078u 6.7.2 Blob Magick[2932]: blob.c/OpenBl
ob/2482/Blob
    read 3 magic header bytes
2011-10-02T21:33:09+11:00 0:00.182 0.078u 6.7.2 Cache Magick[2932]: cache.c/Dest
royPixelCache/1505/Cache
  destroy
2011-10-02T21:33:09+11:00 0:00.185 0.078u 6.7.2 Coder Magick[2932]: icon.c/ReadI
CONImage/216/Coder
  CAD_AAA.ico
2011-10-02T21:33:09+11:00 0:00.189 0.078u 6.7.2 Policy Magick[2932]: policy.c/Is
RightsAuthorized/485/Policy
  Domain: Path; rights=Read; pattern="CAD_AAA.ico" ...
2011-10-02T21:33:09+11:00 0:00.193 0.078u 6.7.2 Blob Magick[2932]: blob.c/OpenBl
ob/2482/Blob
    read 3 magic header bytes
2011-10-02T21:33:09+11:00 0:00.199 0.078u 6.7.2 Module Magick[2932]: module.c/Op
enModule/1264/Module
  Searching for module "PNG" using filename "IM_MOD_RL_PNG_.dll"
2011-10-02T21:33:09+11:00 0:00.204 0.078u 6.7.2 Module Magick[2932]: module.c/Ge
tMagickModulePath/565/Module
  Searching for coder module file "IM_MOD_RL_PNG_.dll" ...
2011-10-02T21:33:09+11:00 0:00.208 0.078u 6.7.2 Configure Magick[2932]: nt-base.
c/NTRegistryKeyLookup/1661/Configure
  SOFTWARE\ImageMagick\6.7.2\Q:16
2011-10-02T21:33:09+11:00 0:00.214 0.078u 6.7.2 Configure Magick[2932]: nt-base.
c/NTRegistryKeyLookup/1679/Configure
  CoderModulesPath
2011-10-02T21:33:09+11:00 0:00.219 0.078u 6.7.2 Module Magick[2932]: module.c/Op
enModule/1273/Module
  Opening module at path "C:\Program Files\ImageMagick-6.7.2-Q16\modules\coders\
IM_MOD_RL_PNG_.dll"
2011-10-02T21:33:09+11:00 0:00.226 0.078u 6.7.2 Module Magick[2932]: module.c/Op
enModule/1300/Module
  Method "RegisterPNGImage" in module "PNG" at address 6AA95A30
2011-10-02T21:33:09+11:00 0:00.232 0.078u 6.7.2 Module Magick[2932]: module.c/Op
enModule/1314/Module
  Method "UnregisterPNGImage" in module "PNG" at address 6AA8A360
2011-10-02T21:33:09+11:00 0:00.237 0.078u 6.7.2 Cache Magick[2932]: cache.c/Dest
royPixelCache/1505/Cache
  destroy
2011-10-02T21:33:09+11:00 0:00.241 0.078u 6.7.2 Policy Magick[2932]: policy.c/Is
RightsAuthorized/485/Policy
  Domain: Coder; rights=Read; pattern="PNG" ...
2011-10-02T21:33:09+11:00 0:00.247 0.078u 6.7.2 Coder Magick[2932]: png.c/ReadPN
GImage/3633/Coder
  Enter ReadPNGImage()
2011-10-02T21:33:09+11:00 0:00.250 0.078u 6.7.2 Coder Magick[2932]: png.c/ReadOn
ePNGImage/2069/Coder
    Enter ReadOnePNGImage()
2011-10-02T21:33:09+11:00 0:00.254 0.078u 6.7.2 Coder Magick[2932]: png.c/ReadOn
ePNGImage/2098/Coder
    image->matte=0
2011-10-02T21:33:09+11:00 0:00.258 0.078u 6.7.2 Coder Magick[2932]: png.c/Magick
PNGErrorHandler/1725/Coder
    libpng-1.5.4 error: [01][00][20][00]: invalid chunk type
2011-10-02T21:33:09+11:00 0:00.264 0.094u 6.7.2 Exception Magick[2932]: png.c/Ma
gickPNGErrorHandler/1728/Exception
  [01][00][20][00]: invalid chunk type `CAD_AAA.ico'
2011-10-02T21:33:09+11:00 0:00.268 0.094u 6.7.2 Coder Magick[2932]: png.c/ReadOn
ePNGImage/2153/Coder
    exit ReadOnePNGImage() with error.
2011-10-02T21:33:09+11:00 0:00.272 0.094u 6.7.2 Coder Magick[2932]: png.c/ReadPN
GImage/3692/Coder
  exit ReadPNGImage() with error.
2011-10-02T21:33:09+11:00 0:00.276 0.109u 6.7.2 Exception Magick[2932]: png.c/Re
adPNGImage/3695/Exception
  corrupt image `CAD_AAA.ico'
2011-10-02T21:33:09+11:00 0:00.282 0.109u 6.7.2 Cache Magick[2932]: cache.c/Dest
royPixelCache/1505/Cache
  destroy
2011-10-02T21:33:09+11:00 0:00.285 0.109u 6.7.2 Cache Magick[2932]: cache.c/Dest
royPixelCache/1505/Cache
  destroy
2011-10-02T21:33:09+11:00 0:00.289 0.109u 6.7.2 Exception Magick[2932]: convert.
c/ConvertImageCommand/3016/Exception
  missing an image filename `CAD_AAA.png'
Magick: [01][00][20][00]: invalid chunk type `CAD_AAA.ico' @ error/png.c/MagickP
NGErrorHandler/1728.
Magick: corrupt image `CAD_AAA.ico' @ error/png.c/ReadPNGImage/3695.
Magick: missing an image filename `CAD_AAA.png' @ error/convert.c/ConvertImageCo
mmand/3016.


Re: "Invalid chunk type" when converting .ico to .png

Posted: 2011-10-03T06:16:46-07:00
by glennrp
This forum doesn't accept attachments. You could send a copy of the problematic ICO file to
glennrp at gmail.com and I'll have a look.

Re: "Invalid chunk type" when converting .ico to .png

Posted: 2011-10-03T09:17:05-07:00
by fmw42
Would like to attach the icon but as this is my first post, I don't know how to do it yet.
You can upload your image to any free image hosting web site and then post the link to the image on that web site here in your post.

Re: "Invalid chunk type" when converting .ico to .png

Posted: 2011-10-04T17:38:53-07:00
by glennrp
They are huge files, about .5MB each.

"strings" doesn't find any PNG chunks, so they apparently aren't PNG-encoded, yet
ImageMagick is trying to use the PNG decoder on them.

Old code based on ImageMagick-5.5.7 is able to "identify" them, reporting
  • MM-resourcer.ico[1] ICO 128x128+0+0 DirectClass 8-bit 466.3K 0.010u 0:01
    MM-resourcer.ico[2] ICO 64x64+0+0 DirectClass 8-bit 466.3K 0.010u 0:01
    MM-resourcer.ico[3] ICO 48x48+0+0 DirectClass 8-bit 466.3K 0.010u 0:01
    MM-resourcer.ico[4] ICO 32x32+0+0 DirectClass 8-bit 466.3K 0.010u 0:01
    MM-resourcer.ico[5] ICO 16x16+0+0 DirectClass 8-bit 466.3K 0.010u 0:01
    MM-resourcer.ico[6] ICO 0x0+0+0 DirectClass 8-bit 466.3K 0.010u 0:01
    MM-resourcer.ico[7] ICO 128x128+0+0 DirectClass 8-bit 466.3K 0.010u 0:01
    MM-resourcer.ico[8] ICO 64x64+0+0 DirectClass 8-bit 466.3K 0.010u 0:01
    MM-resourcer.ico[9] ICO 48x48+0+0 DirectClass 8-bit 466.3K 0.010u 0:01
    MM-resourcer.ico[10] ICO 32x32+0+0 DirectClass 8-bit 466.3K 0.010u 0:01
    MM-resourcer.ico[11] ICO 16x16+0+0 DirectClass 8-bit 466.3K 0.000u 0:01
Note that it contains two pyramids, and two 0x0 images.

If anyone else wants to take a look, they are at http://glennrp.net/IM/bad_ico
individually and in a bad_ico.tar.gz tarball.

Re: "Invalid chunk type" when converting .ico to .png

Posted: 2011-10-04T18:49:48-07:00
by magick
ImageMagick assumes an embedded PNG image with the ICON when it sees a width / height of 0. That's not the case for these images. We need to properly determine how to identify an embedded PNG image in an ICON.

Re: "Invalid chunk type" when converting .ico to .png

Posted: 2011-10-05T03:47:43-07:00
by glennrp
A PNG would have an IHDR chunk at or near the beginning of the PNG datastream.

From the spec dexcribed here
http://en.wikipedia.org/wiki/ICO_%28file_format%29
it appears that each subimage can be in PNG or not, independently, so we have
to find the beginning of each image and check. It seems to say that the
8-byte PNG signature is included with each PNG subimage.

0x0 according to the spec means 256x256, which is evidently the case with the
test images.