[Mono-bugs] [Bug 24691] New - S.T.ASCII.GetString() differs from MS implementation

bugzilla-daemon@rocky.ximian.com bugzilla-daemon@rocky.ximian.com
14 May 2002 15:54:57 -0000


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 ipmccmono@hotmail.com.

http://bugzilla.ximian.com/show_bug.cgi?id=24691

--- shadow/24691	Tue May 14 11:54:57 2002
+++ shadow/24691.tmp.5192	Tue May 14 11:54:57 2002
@@ -0,0 +1,74 @@
+Bug#: 24691
+Product: Mono/Class Libraries
+Version: unspecified
+OS: Red Hat 7.2
+OS Details: 
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Normal
+Component: System
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: ipmccmono@hotmail.com               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: S.T.ASCII.GetString() differs from MS implementation
+
+Description of Problem:
+
+The method System.Text.ASCIIEncoding.GetString(Byte[], Int32, Int32) 
+differs from the Microsoft implementation in its validation of arguments. 
+MS's implementation allows byteCount to be 0, but mono throws an exception.
+
+Under VS.NET the following is legal, but causes a runtime exception on 
+mono.
+using System;
+using System.Text;
+
+class Test
+{
+    static void Main()
+    {
+        //just an excuse to get a byte array
+        byte[] myArr = Encoding.ASCII.GetBytes("hello".ToCharArray());
+        // this is where the problem is:
+        string myStr = Encoding.ASCII.GetString(myArr, 0, 0);
+    }
+}
+
+
+
+Steps to reproduce the problem:
+1. Compile the source above
+2. Watch it fail.
+
+Actual Results:
+
+System.ArgumentOutOfRangeException: "Argument is out of range"
+in 09d System.Text.ASCIIEncoding:GetString ()
+in 060 .Test:Main ()
+
+Expected Results:
+
+For it to work
+
+How often does this happen? 
+
+Reliably
+
+Additional Information:
+Here's a fix (I added the if statement to prevent any cascading 
+repurcussions down the call chain):
+$ diff ASCIIEncoding.cs myASCIIEncoding.cs
+157c157
+<                       if ((byteIndex < 0) || (byteCount <= 0) ||
+---
+>                       if ((byteIndex < 0) || (byteCount < 0) ||
+160c160,162
+<
+---
+>
+>                       if (byteCount == 0)
+>                               return "";