Skip to content

Invalid PNG metadata when ICONDIRENTRY has a bitCount of zero #13

@rosasurfer

Description

@rosasurfer

Thank you for this little libray. I face an issue with a specific icon which has mixed BMP and PNG images. In this case it's a 256x256 PNG contained in ResourceHacker's main executable:
http://angusj.com/resourcehacker/

If an icon contains a PNG image and in ICONDIRENTRY the PNG's bitCount is set to zero the value in IconImage is not updated to the PNG's real bit depth.

How to reproduce:

$service = new IcoFileService();
$icon = $service->from(file_get_contents('http://rosasurfer.com/.intern/mixed.ico'));
/** @var IconImage $image */
foreach ($icon as $image) {
    echo $image->getDescription().PHP_EOL;
}

Expected result:

256x256 pixel PNG @ 32 bits/pixel
64x64 pixel BMP @ 32 bits/pixel
48x48 pixel BMP @ 32 bits/pixel
40x40 pixel BMP @ 32 bits/pixel
32x32 pixel BMP @ 32 bits/pixel
24x24 pixel BMP @ 32 bits/pixel
20x20 pixel BMP @ 32 bits/pixel
16x16 pixel BMP @ 32 bits/pixel

Actual result:

256x256 pixel PNG @ 0 bits/pixel
64x64 pixel BMP @ 32 bits/pixel
48x48 pixel BMP @ 32 bits/pixel
40x40 pixel BMP @ 32 bits/pixel
32x32 pixel BMP @ 32 bits/pixel
24x24 pixel BMP @ 32 bits/pixel
20x20 pixel BMP @ 32 bits/pixel
16x16 pixel BMP @ 32 bits/pixel

I worked around it by adding the following snippet to IconParser::parseIconDirEntries() but I don't know the header format good enough and suspect I break cases where a bitCount of zero has a different valid meaning.

if ($icoDirEntry['bitCount'] == 0) {
    $icoDirEntry['bitCount'] = 32;
}

Wouldn't it be better to parse the actual PNG header instead of using possibly conflicting ICONDIRENTRY values? I use this little library which only needs to read the first 29 bytes of a PNG:
https://github.com/ktomk/Miscellaneous/tree/master/get_png_imageinfo

Another note: All internal parser methods are private and there is no way to re-use your class. Can you consider making them protected?

Thank you again.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions