Urgent.News

What's breaking now, across thousands of outlets.

Tech

PNG entries in an .ico: who can actually read them

The favicon tool in an image editor I run used to write every entry in its favicon.ico as a PNG. Browsers are fine with that. Then I loaded the file with System.Drawing from Windows PowerShell, and it threw: Exception calling "ToBitmap" with "0" argument(s): "Requested range extends past the end of the array." The file was not corrupt. Every byte of the container was legal. The payload encoding…

A PNG inside an ICO file can be read by some Windows applications but not others. The issue lies within the System.Drawing library in Windows PowerShell. The library handles PNG entries differently depending on the target framework of the host application. Older versions of the library default to not supporting PNG frames in icons, causing the exception "Requested range extends past the end of the array."

This can affect tools, build scripts, installers, and older WinForms applications that use System.Drawing with the legacy default setting. To resolve the issue, one can either write the favicon as uncompressed 32-bit DIB or only use PNG entries for the 256x256 size. Additionally, the DIB entry must follow specific rules, including doubling the height field, having rows go bottom-up, using BGRA channels instead of RGBA, and ensuring the AND mask exists and is padded correctly.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

More from Wednesday 30 September →