[Mono-bugs] [Bug 324630] ArrayOutOfBounds in BigInteger class

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Thu Jul 3 11:48:38 EDT 2008


https://bugzilla.novell.com/show_bug.cgi?id=324630

User msafar at novell.com added comment
https://bugzilla.novell.com/show_bug.cgi?id=324630#c2


Marek Safar <msafar at novell.com> changed:

           What    |Removed                                         |Added
----------------------------------------------------------------------------
                 CC|                                                |spouliot at novell.com
             Status|ASSIGNED                                        |NEEDINFO
      Info Provider|                                                |amcgovern at novell.com




--- Comment #2 from Marek Safar <msafar at novell.com>  2008-07-03 09:48:37 MDT ---
I spent some time looking into this issue and it seems to be a bug in MS
runtime.

gmcs emits fairly similar code, but we are using pointers (T*) whereas csc uses
references (T&) for array access. That's the only difference which I found.

The issue seems to either in 

public static unsafe BigInteger Reduce (BigInteger n, BigInteger m, uint
mPrime)
or
public static unsafe void SquarePositive (BigInteger bi, ref uint [] wkSpace)
or in both.

there is probably a race somewhere which twists one bit which later get
propagates due to way how is the value normalized.

following logging shows the problem:

bi.length <<= 1;

//////////////////////////////
if (bi.length != wkSpace.Length)
        Console.WriteLine (">> {0} {1} {2}", bi.length, wkSpace.Length, dl <<
1);
/////////////////////////////

// Normalize length
while (bi.length > 1 && tt [bi.length-1] == 0) bi.length--;


LOG RESULT

>> 50 48 50
>> 50 48 50
>> 52 48 52
>> 3720432480 -1772792230 56
System.AccessViolationException: Attempted to read or write protected memory.
Th
is is often an indication that other memory is corrupt.
   at Mono.Math.BigInteger.Kernel.SquarePositive(BigInteger bi, UInt32[]&
wkSpac
e)
   at Mono.Math.BigInteger.ModulusRing.OddPow(BigInteger b, BigInteger exp)
   at Foo.Calculator.Calculate()
System.NullReferenceException: Object reference not set to an instance of an
obj
ect.
   at Mono.Math.BigInteger.Normalize()
   at Mono.Math.BigInteger.BitCount()
   at Mono.Math.BigInteger.ModulusRing.OddPow(BigInteger b, BigInteger exp)
   at Foo.Calculator.Calculate()



The reason why I believe it's .NET issue is due to following workaround which
fixed the crash on .NET.


In method "public static unsafe BigInteger Reduce (BigInteger n, BigInteger m,
uint mPrime)" add

System.Threading.Thread.Sleep (0);

before very last line "return A;", this is very strange but it fixes the issue
for me.


-- 
Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.


More information about the mono-bugs mailing list