[Mono-bugs] [Bug 57379][Wis] New - Bitmap(stream) fails for PNGs

bugzilla-daemon@bugzilla.ximian.com bugzilla-daemon@bugzilla.ximian.com
Wed, 21 Apr 2004 21:17:13 -0400 (EDT)

Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by david.mitchell@telogis.com.


--- shadow/57379	2004-04-21 21:17:13.000000000 -0400
+++ shadow/57379.tmp.2610	2004-04-21 21:17:13.000000000 -0400
@@ -0,0 +1,64 @@
+Bug#: 57379
+Product: Mono: Class Libraries
+Version: unspecified
+OS Details: Redhat 9.0 with libpng 1.2.2
+Status: NEW   
+Priority: Wishlist
+Component: Sys.Drawing.
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: david.mitchell@telogis.com               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+Summary: Bitmap(stream) fails for PNGs
+Please fill in this template when reporting a bug, unless you know what you
+are doing.
+Description of Problem:
+When you try to load a PNG from a file using new Bitmap(string) it works
+fine, but if you try to load the same bitmap from a stream then GDIPlus
+gives an invalid argument exception. I've tracked this down to gdipFunctions.cs
+In StreamGetBytesImpl it checks to make sure the buffer size is at least as
+big as the peekBytes buffer (if it exists). It fails it the buffer size is
+too small. Problem is, when GdipLoadImageFromDelegate_linux (in image.c)
+checks the image format it peeks 10 bytes. The first thing png_read_png
+does is read 8 bytes, hence the previously mentioned check fails (reading 8
+bytes when peekBytes buffer length is 10 returns -1) and the image load fails.
+Steps to reproduce the problem:
+1. Compile the attached test (mcs -r:System.Drawing piccy.cs)
+2. Run (mono piccy.cs)
+3. Watch it die
+Actual Results:
+Expected Results:
+How often does this happen? 
+Additional Information:
+using System.Drawing;
+using System.IO;
+class Piccy {
+    public static void Main() {
+        FileStream f = new FileStream("foo.png", FileMode.Open);
+        Bitmap b = new Bitmap(f);
+        b.Dispose();
+    }
+end piccy.cs
+Use any foo.png you like as long as it is a valid PNG image.