2010-07-06 Atsushi Enomoto <atsushi@ximian.com>
authorAtsushi Eno <atsushieno@gmail.com>
Tue, 6 Jul 2010 15:53:46 +0000 (15:53 -0000)
committerAtsushi Eno <atsushieno@gmail.com>
Tue, 6 Jul 2010 15:53:46 +0000 (15:53 -0000)
* XmlInputStream.cs : it had been failing to retrieve correct
  encoding due to insufficient buffer reading. Fixed bug #615499.

svn path=/trunk/mcs/; revision=159967

mcs/class/System.XML/System.Xml/ChangeLog
mcs/class/System.XML/System.Xml/XmlInputStream.cs

index ce917ae240bb40ca08e5ce9cac3f22004cb2b84a..cfff07c907b739d35322059bf35521fd4d9d824e 100644 (file)
@@ -1,3 +1,8 @@
+2010-07-06  Atsushi Enomoto  <atsushi@ximian.com>
+
+       * XmlInputStream.cs : it had been failing to retrieve correct
+         encoding due to insufficient buffer reading. Fixed bug #615499.
+
 2010-06-30  Atsushi Enomoto  <atsushi@ximian.com>
 
        * XmlDefaultWriter.cs : add state management support. 
index 2e4e135f1e4d93d8796055320c9f6c3876bb1d6d..03582af44e80b09d13859c0eb3fc0f08f66b9646 100644 (file)
@@ -64,8 +64,8 @@ namespace System.Xml
                                return base.Read (dest_buffer, index, count);
                        }
 #if NET_1_1
-                       catch (System.ArgumentException) {
-                               throw invalidDataException;
+                       catch (System.ArgumentException ex) {
+                               throw new XmlException ("Invalid data", ex);
                        }
 #else
                        catch (System.Text.DecoderFallbackException) {
@@ -359,16 +359,22 @@ namespace System.Xml
                        Initialize (stream);
                }
 
-               static string GetStringFromBytes (byte [] bytes, int index, int count)
+               // this returns null, instead of throwing ArgumentOutOfRangeException
+               string GetStringFromBytes (int index, int count)
                {
+                       int posBak = bufPos;
+                       while (bufPos < index + count)
+                               if (ReadByteSpecial () < 0)
+                                       return null;
+                       bufPos = posBak;
 #if MOONLIGHT
                        char [] chars = new char [count];
                        for (int i = index; i < count; i++)
-                               chars [i] = (char) bytes [i];
+                               chars [i] = (char) buffer [i];
 
                        return new string (chars);
 #else
-                       return Encoding.ASCII.GetString (bytes, index, count);
+                       return Encoding.ASCII.GetString (buffer, index, count);
 #endif
                }
 
@@ -418,7 +424,7 @@ namespace System.Xml
                                break;
                        case '<':
                                // try to get encoding name from XMLDecl.
-                               if (bufLength >= 5 && GetStringFromBytes (buffer, 1, 4) == "?xml") {
+                               if (bufLength >= 5 && GetStringFromBytes (1, 4) == "?xml") {
                                        bufPos += 4;
                                        c = SkipWhitespace ();
 
@@ -435,8 +441,7 @@ namespace System.Xml
                                        }
 
                                        if (c == 'e') {
-                                               int remaining = bufLength - bufPos;
-                                               if (remaining >= 7 && GetStringFromBytes (buffer, bufPos, 7) == "ncoding") {
+                                               if (GetStringFromBytes (bufPos, 7) == "ncoding") {
                                                        bufPos += 7;
                                                        c = SkipWhitespace();
                                                        if (c != '=')