Bug 11058 - Number overflow in __icall_wrapper_mono_array_new_specific
Summary: Number overflow in __icall_wrapper_mono_array_new_specific
Status: RESOLVED FIXED
Alias: None
Product: Runtime
Classification: Mono
Component: JIT ()
Version: unspecified
Hardware: PC Linux
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2013-03-11 19:15 UTC by Matthias Linder
Modified: 2013-03-13 05:52 UTC (History)
3 users (show)

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

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 on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Matthias Linder 2013-03-11 19:15:58 UTC
Apparently mono internally uses an untruncated data type for the length when trying to create a new array, while only displaying a 
truncated data type to the .NET environment. It might be possible that this problem only occurs on 64-bit systems. 

Code to reproduce:

using System;
class P {
  static void Main() {
    int foo = -252674008;
    int foo2 = (int)(foo ^ 0xF0F0F0F0); // = 28888
    if ((foo2 & 0xFFFF) == foo2) Console.WriteLine("a) and b) are equal");
    Console.WriteLine("a) "+new byte[foo2 & 0xFFFF].Length); // works fine
    Console.WriteLine("b) "+new byte[foo2].Length); // NumberOverflow
  }
}


foo2 should be 28888, and thus & 0xFFFF should not perform any change here. .NET tells us that both values are the same. Yet the first array creation works fine, while the second statement will crash with an overflow exception:

> mono monoBug.exe
a) and b) are equal
a) 28888

[ERROR] FATAL UNHANDLED EXCEPTION: System.OverflowException: Number overflow.
  at (wrapper managed-to-native) object:__icall_wrapper_mono_array_new_specific (intptr,int)
  at P.Main () [0x00000] in <filename unknown>:0 


Expected behavior: 28888 should be 28888 ...


I'm running Ubuntu 64-bit and tried these two different mono versions: 2.10.8.1 (Debian 2.10.8.1-5ubuntu1), and 3.0.6 (Debian 3.0.6+dfsg-1~exp1~pre1)
Comment 1 Zoltan Varga 2013-03-12 16:32:28 UTC
Fixed in master.
Comment 2 Matthias Linder 2013-03-13 05:52:42 UTC
Great! Thanks.