Bug 30715 - System.Drawing.Icon causes crash when loading an .ICO file containing an PNG image
Summary: System.Drawing.Icon causes crash when loading an .ICO file containing an PNG ...
Status: NEW
Alias: None
Product: Class Libraries
Classification: Mono
Component: System.Drawing ()
Version: 4.0.0
Hardware: PC Windows
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2015-06-03 09:10 UTC by joona.o.heikkila
Modified: 2015-07-22 17:25 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
Icon samples (11.47 KB, application/octet-stream)
2015-06-03 09:10 UTC, joona.o.heikkila
Details
Adds support for PNG in ICO files. (8.92 KB, patch)
2015-07-22 08:36 UTC, ediazfer
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report for Bug 30715 on GitHub or Developer Community if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: GitHub Markdown or Developer Community HTML
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:
Status:
NEW

Description joona.o.heikkila 2015-06-03 09:10:45 UTC
Created attachment 11448 [details]
Icon samples

Library:   System.Drawing.dll
Namespace: System.Drawing
Class:     System.Drawing.Icon
Method:    Icon.InitFromStreamWithSize (Stream stream, int width, int height)

https://github.com/mono/mono/blob/master/mcs/class/System.Drawing/System.Drawing/Icon.cs#L850


When constructing a new instance of the Icon class with an .ico file on disk
which contains an PNG image instead of BMP/DIP, an OutOfMemoryException is
thrown:


    C:\Program Files (x86)\Mono\bin
    λ mono --debug F:\Program.exe

    Unhandled Exception:
    OutOfMemoryException
    [ERROR] FATAL UNHANDLED EXCEPTION: System.OutOfMemoryException: Out of memory
      at (wrapper managed-to-native) object:__icall_wrapper_mono_gc_alloc_vector (intptr,intptr,intptr)
      at (wrapper alloc) object:AllocVector (intptr,intptr)
      at System.Drawing.Icon.InitFromStreamWithSize (System.IO.Stream stream, Int32 width, Int32 height) [0x0053e]     in C:\buildroot\release\repos\mono\mcs\class\System.Drawing\System.Drawing\Icon.cs:845
      at System.Drawing.Icon..ctor (System.String fileName) [0x00018] in     C:\buildroot\release\repos\mono\mcs\class\System.Drawing\System.Drawing\Icon.cs:224
      at (wrapper remoting-invoke-with-check) System.Drawing.Icon:.ctor (string)
      at Program.Main () [0x00000] in <filename unknown>:0


If using an .ico file which' dimensions are 256x256, an Win32Exception is thrown, but it seems like that is caused by a missing implementation instead of a bug: https://github.com/mono/mono/blob/master/mcs/class/System.Drawing/System.Drawing/Icon.cs#L725



mcs command line:

    mcs -r:System.Drawing F:/Program.cs

mono command line:

    mono --debug F:/Program.cs

Sample program:

    using System;
    using System.Drawing;
    public static class Program
    {
        public static void Main()
        {
            new Icon("F:/icon.ico");
        }
    }

Icon samples attached.
Comment 1 ediazfer 2015-07-22 08:36:25 UTC
Created attachment 12156 [details]
Adds support for PNG in ICO files.

I've just rebuild mono with this and was able to go beyond the xbuild issue on my vs15 csproj.
Comment 2 joona.o.heikkila 2015-07-22 14:12:54 UTC
Looks like your IDE switched the tabs to spaces.
Comment 3 ediazfer 2015-07-22 17:25:25 UTC
I wrote that using vim to avoid reformatting : my style is relatively different from the original source's.  This would have led to a much bigger patch.

I assume any IDE would re-indent using one's choice.