[Mono-bugs] [Bug 431001] Exception using XmlTextReader after stream is disposed

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Tue Oct 7 04:58:45 EDT 2008


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

User atsushi at ximian.com added comment
https://bugzilla.novell.com/show_bug.cgi?id=431001#c4


Atsushi Enomoto <atsushi at ximian.com> changed:

           What    |Removed                                         |Added
----------------------------------------------------------------------------
             Status|NEW                                             |RESOLVED
         Resolution|                                                |INVALID




--- Comment #4 from Atsushi Enomoto <atsushi at ximian.com>  2008-10-07 02:58:44 MDT ---
The sample code has wrong premise as if a disposed Stream were read. This
premise is all wrong. If you have the sample schema bigger than 4096 bytes,
NET immediately gives you ObjectDisposedException for attempt to disposed
stream. You are lucky only because the schema is only of the length 1397 bytes.
Add more about 3000 bytes of whitespaces before <schema> element, and you can
never succeed.

The reason why .NET reads 4096 bytes from the stream is not known, but it is
only part of implementation details. We consume only 64 bytes to detect
encoding from XML declaration (which is mandatory), and does not read further
pointlessly.

You can see how the input stream is consumed by this modified example below:

----
using System;
using System.IO;
using System.Xml;
using System.Xml.Schema;

public class Invoke
{
        public static void Main ()
        {
                Stream stream = new MyStream ("431001.xsd", FileMode.Open);
                Console.WriteLine ("###");
                XmlTextReader schemaReader = new XmlTextReader (new
StreamReader
 (stream));
                Console.WriteLine ("###");
                stream.Dispose ();
                Console.WriteLine ("###");

                Console.WriteLine ("###");
                XmlReaderSettings settings = new XmlReaderSettings ();
                Console.WriteLine ("###");
                settings.Schemas.Add
("http://schemas.microsoft.com/pag/cab-profile", schemaReader);
                Console.WriteLine ("###");
                foreach (XmlSchema xs in settings.Schemas.Schemas ())
                        xs.Write (Console.Out);
        }
}

public class MyStream : FileStream
{
        public MyStream (string file, FileMode mode)
                : base (file, mode)
        {
        }

        public override int Read (byte [] buffer, int offset, int count)
        {
                Console.WriteLine ("READ(buf,{0},{1})", offset, count);
                return base.Read (buffer, offset, count);
        }
}
--------

Marking the bug as INVALID.


-- 
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