mono/mono — pull request #439 by gary-b (2012-08-21 17:16:21+00:00)
Title: Garyb/iconfix

This is a fix for bugs
Novell: (2008)
https://bugzilla.novell.com/show_bug.cgi?id=415809
Xamarin:
https://bugzilla.xamarin.com/show_bug.cgi?id=6451
Realated:
https://bugzilla.xamarin.com/show_bug.cgi?id=3961

The bug centres around support for Windows Vista style Icons which include a larger 256x256 image which by design guidelines should be of png type. When mono encounters an icon like this it simply does not load the image data nor keep a copy of the IconDir header entry for it. The problem comes when writing the icon back again, it does not include the image data and the rest of the IconDir header entries have offsets which haven't been recalculated to account for the data removal rendering the icon file corrupt.

A simpler fix is to recalculate the offsets so the icon does not become corrupted. This however means that mono is silently degrading the icon file without informing the user. The patch provided keeps a copy of the image data and its corresponding header entry so it can be written back. It also updates logic so that the image is ignored during the normal functioning of the class.

Note the FIXME: at line 412: The icon attached to bug report 6451 seems to have additional bytes between some images in the file which the code highlighted handles. Microsoft doesn't have an exact spec for the ico format that I could find, Wikipedia seems to be the best account and makes no mention of this. The icon is from Microsoft as far as I can tell (and thus I am hesitant to include it as a test). I tested a number of others but none had the additional bytes between images. Ill leave it to you to decide whether this code should be included or not.