Skip to content

Carefully crafted ICO can trigger a fatal error #22

@offsky

Description

@offsky

I ran into a situation with an ico image where IcoParser->isPNG($data) passed, but then imagecreatefromstring($data) failed. The result is that in parsePNGAsIco() it crashes with a fatal error when it gets to the imagesx(false) line. Here is the bug fix:

private function parsePNGAsIco($data)
    {
        $png = imagecreatefromstring($data);
+       if (!$png) {
+           throw new \InvalidArgumentException('Invalid PNG file format');
+       }
        $w = imagesx($png);
        $h = imagesy($png);

Here is the icon that triggered the error for me.
favicon.ico.zip

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