icofileloader icon indicating copy to clipboard operation
icofileloader copied to clipboard

Carefully crafted ICO can trigger a fatal error

Open offsky opened this issue 10 months ago • 1 comments

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

offsky avatar Mar 27 '24 16:03 offsky

Thanks for this - I'll try and incorporate this into a new release in next few days

lordelph avatar Mar 27 '24 17:03 lordelph