Bugzilla – Bug 314971
[PATCH] Wrong exception when allocating an array of a negative (or unsigned) size
Last modified: 2007-09-15 21:24:46 UTC
---- Reported by sebastien@ximian.com 2004-06-03 10:45:23 MST ---- Description of Problem: Mono throws a OutOfMemoryException where the MS runtime throws a OverflowException. Steps to reproduce the problem: 1. Compile the following source using System; class UnsignedSizedArray { static void Main () { try { Console.WriteLine ("new byte [Int32.MaxValue + 1]"); byte[] mem = new byte [0x80000000]; } catch (OverflowException e) { Console.WriteLine ("Overflow"); } catch (OutOfMemoryException) { Console.WriteLine ("OutOfMemory"); } catch (Exception e) { Console.WriteLine ("Oops ? {0}", e.ToString ()); } } } 2. Execute it Actual Results (mono runtime): new byte [Int32.MaxValue + 1] GC Warning: Out of Memory! Returning NIL! OutOfMemory Expected Results (ms runtime): new byte [Int32.MaxValue + 1] Overflow How often does this happen? Always Additional Information: Throwing the OverflowException from the runtime could have the same effect as detailled in https://bugzilla.novell.com/show_bug.cgi?id=MONO59509 ---- Additional Comments From bmaurer@users.sf.net 2004-08-27 20:54:42 MST ---- Created an attachment (id=166174) patch ---- Additional Comments From bmaurer@users.sf.net 2004-08-27 20:55:57 MST ---- * object.c: check that array lengths are not negative (and throw S.OverflowException if they are) before doing OOM checks. ---- Additional Comments From vargaz@freemail.hu 2004-09-02 10:04:33 MST ---- This is OK to check in. ---- Additional Comments From bmaurer@users.sf.net 2004-09-06 10:04:02 MST ---- It's in cvs Imported an attachment (id=166174)