[Mono-bugs] [Bug 589236] New: StreamReader class raise IndexOutOfRangeException

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Wed Mar 17 22:11:14 EDT 2010


http://bugzilla.novell.com/show_bug.cgi?id=589236

http://bugzilla.novell.com/show_bug.cgi?id=589236#c0


           Summary: StreamReader class raise IndexOutOfRangeException
    Classification: Mono
           Product: Mono: Class Libraries
           Version: SVN
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: Normal
          Priority: P5 - None
         Component: CORLIB
        AssignedTo: mono-bugs at lists.ximian.com
        ReportedBy: laneser.kuo at gmail.com
         QAContact: mono-bugs at lists.ximian.com
          Found By: ---
           Blocker: ---


User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US)
AppleWebKit/533.2 (KHTML, like Gecko) Chrome/5.0.342.5 Safari/533.2

becuase of auto-detecting encoding in StreamReader,
it will change the encoder, but forget to change decoded_buffer size.

bug 411861 and 534137 may be related to the bug because of auto-detect
encoding.

I suggest change to code inside StreamReader.ReadBuffer()
..
parse_start = DoChecks (cbEncoded);
if (old != encoding){
    decoder = encoding.GetDecoder ();
        // Change the decoded_buffer after decoder changed.
        // in order to prevent the IndexOutOfRangeException when decode.
    decoded_buffer = new char [encoding.GetMaxCharCount (this.buffer_size) +
1];
}
..

Reproducible: Always

Steps to Reproduce:
the following code should reproduce the bug:

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace TestProgram
{
    class Program
    {
        static void Main(string[] args)
        {
            // to test StreamReader.cs bug in mono
            int testlines = 2048; // all data should larger than stream reader
default buffer size
            string testdata = "test";

            MemoryStream ms = new MemoryStream();
            // write utf8 encoding data.
            using (StreamWriter sw = new StreamWriter(ms, Encoding.UTF8))
            {
                for (int i = 0; i < testlines; i++)
                    sw.WriteLine(testdata);
            }

            MemoryStream readms = new MemoryStream(ms.GetBuffer());

            // read from streamreader and let streamreader detect encoding
            using (StreamReader sr = new StreamReader(readms, Encoding.Unicode,
true))
                for (int i = 0; i < testlines; i++)
                {
                    string line = sr.ReadLine();
                    if (line != testdata)
                        Console.WriteLine("read data error : " + line + " , but
should be " + testdata);
                }

            Console.WriteLine("check over");
            Console.ReadLine();
        }
    }
}

Actual Results:  
Unhandled Exception: System.IndexOutOfRangeException: Array index is out of
range.
  at System.IO.StreamReader.FindNextEOL () [0x00000]
  at System.IO.StreamReader.ReadLine () [0x00000]
  at ConsoleApplication67.Program.Main (System.String[] args) [0x00000]

Expected Results:  
mono should execute the code without exceptions.

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


More information about the mono-bugs mailing list