[Mono-bugs] [Bug 77195][Maj] New - BitArray.CopyTo throws
ArgumentException when 0-length BitArray is copied
bugzilla-daemon at bugzilla.ximian.com
bugzilla-daemon at bugzilla.ximian.com
Tue Jan 10 10:41:41 EST 2006
Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.
Changed by monobugzilla at bakta.org.
http://bugzilla.ximian.com/show_bug.cgi?id=77195
--- shadow/77195 2006-01-10 10:41:41.000000000 -0500
+++ shadow/77195.tmp.5190 2006-01-10 10:41:41.000000000 -0500
@@ -0,0 +1,123 @@
+Bug#: 77195
+Product: Mono: Class Libraries
+Version: unspecified
+OS: All
+OS Details:
+Status: NEW
+Resolution:
+Severity:
+Priority: Major
+Component: CORLIB
+AssignedTo: mono-bugs at ximian.com
+ReportedBy: monobugzilla at bakta.org
+QAContact: mono-bugs at ximian.com
+TargetMilestone: ---
+URL:
+Summary: BitArray.CopyTo throws ArgumentException when 0-length BitArray is copied
+
+Please fill in this template when reporting a bug, unless you know what you
+are doing.
+Description of Problem:
+
+
+Steps to reproduce the problem:
+1. Use any System.Collection.BitArray of Length=0
+2. Allocate also Length=0 byte Array
+3. Try to use BitArray.CopyTo(byteArray, 0)
+Example:
+using System;
+using System.Collections;
+
+namespace BitArrTest
+{
+ class Class1
+ {
+ [STAThread]
+ static void Main(string[] args)
+ {
+ ArrayList al = new ArrayList();
+ //al.Add(1);
+ //al.Add(0);
+ BitArray ba = new BitArray(al.Count);
+ for(int i = 0; i < al.Count; i++)
+ if((int)al[i] != 0)
+ ba[i] = true;
+ else
+ ba[i] = false;
+ byte[] bya = new byte[(al.Count+7)/8];
+ ba.CopyTo(bya, 0); // When al empty then ArgumentException here.
+ Console.WriteLine("Done");
+ }
+ }
+}
+
+std compile and run
+
+
+Actual Results:
+fik:~/mono/vt# mono BitArrTest.exe
+
+Unhandled Exception: System.ArgumentException: index
+Parameter name: index is greater than array.Length
+in <0x003d4> System.Collections.BitArray:CopyTo (System.Array array, Int32
+index)
+in <0x00100> BitArrTest.Class1:Main (System.String[] args)
+fik:~/mono/vt#
+
+
+Expected Results:
+Print: Done. (byte array created with length=0, no actual data copy)
+
+How often does this happen?
+allways when destination array is length=0 (
+
+Additional Information:
+
+Possible part:
+
+ public void CopyTo (Array array, int index)
+ {
+ if (array == null)
+ throw new ArgumentNullException ("array");
+ if (index < 0)
+ throw new ArgumentOutOfRangeException ("index");
+
+ if (array.Rank != 1)
+ throw new ArgumentException ("array", "Array rank must be 1");
+
+ if (index >= array.Length) // Possible error here! add || index == 0 ->
+which provides success for 0len to 0len array copy
+ throw new ArgumentException ("index", "index is greater than
+array.Length");
+
+ // in each case, check to make sure enough space in array
+
+ if (array is bool []) {
+ if (array.Length - index < _length)
+ throw new ArgumentException ();
+
+ bool [] barray = (bool []) array;
+
+ // Copy the bits into the array
+ for (int i = 0; i < _length; i++)
+ barray[index + i] = this [i];
+
+ } else if (array is byte []) {
+ int numbytes = (_length + 7) / 8;
+
+ if ((array.Length - index) < numbytes)
+ throw new ArgumentException ();
+
+ byte [] barray = (byte []) array;
+ // Copy the bytes into the array
+ for (int i = 0; i < numbytes; i++)
+ barray [index + i] = getByte (i);
+
+ } else if (array is int []) {
+
+ Array.Copy (_array, 0, array, index, (_length + 31) / 32);
+
+ } else {
+ throw new ArgumentException ("array", "Unsupported type");
+ }
+ }
More information about the mono-bugs
mailing list