Bug 2761 - BigInteger constructed with zero-filled byte array raises IndexOutOfRangeException
Summary: BigInteger constructed with zero-filled byte array raises IndexOutOfRangeExce...
Status: RESOLVED FIXED
Alias: None
Product: Class Libraries
Classification: Mono
Component: System ()
Version: 2.10.x
Hardware: PC Linux
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2012-01-06 13:45 UTC by jordanbtucker
Modified: 2012-01-06 19:36 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 jordanbtucker 2012-01-06 13:45:43 UTC
Overview:
When a System.Numerics.BigInteger type is constructed with a zero-filled byte array with a length of two or greater, a System.IndexOutOfRangeException is raised.


Steps to Reproduce:
Create a C# file with the following code:

class Program {
  static void Main() {
    System.Console.WriteLine(new System.Numerics.BigInteger(new byte[2]));
  }
}

Compile with `dmcs -r:System.Numerics` and run.


Actual Results:
Application crashes with the following error:
Unhandled Exception: System.IndexOutOfRangeException: Array index is out of range.
  at System.Numerics.BigInteger..ctor (System.Byte[] value) [0x00000] in <filename unknown>:0 
  at Program.Main () [0x00000] in <filename unknown>:0 


Expected Results:
Application should output a single line containing the '0' character and exit without error.


Build Date & Platform:
Build 2012-01-06 on Ubuntu 10.04 32-bit with Mono 2.10.5.
Build 2012-01-06 on Windows 7 SP1 64-bit with Mono 2.10.8.


Additional Builds and Platforms:
Does not occur on Build 2012-01-06 on Windows 7 SP1 64-bit using Microsoft .NET Framework 4.0.


Additional Information:
Cause of bug exists on line 254 of BigInteger.cs where a negative index is passed when the byte array contains all zeroes.
https://github.com/mono/mono/blob/mono-2-10-8/mcs/class/System.Numerics/System.Numerics/BigInteger.cs#L254
Comment 1 jordanbtucker 2012-01-06 15:21:11 UTC
Pull request for fix at https://github.com/mono/mono/pull/212
Comment 2 Zoltan Varga 2012-01-06 19:36:10 UTC
-> fixed.