Bug 314971 (MONO59556) - [PATCH] Wrong exception when allocating an array of a negative (or unsigned) size
Summary: [PATCH] Wrong exception when allocating an array of a negative (or unsigned) ...
Status: RESOLVED FIXED
Alias: MONO59556
Product: Mono: Runtime
Classification: Mono
Component: misc (show other bugs)
Version: unspecified
Hardware: Other All
: P3 - Medium : Normal
Target Milestone: ---
Assignee: Ben Maurer
QA Contact: Mono Bugs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-06-03 17:45 UTC by Sebastien Pouliot
Modified: 2007-09-15 21:24 UTC (History)
0 users

See Also:
Found By: ---
Services Priority:
Business Priority:
Blocker: ---
Marketing QA Status: ---
IT Deployment: ---


Attachments
patch (1.33 KB, patch)
2004-08-28 03:54 UTC, Thomas Wiest
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Wiest 2007-09-15 18:40:41 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)