Переглянути джерело

2009-05-19 Atsushi Enomoto <[email protected]>

	* XmlBinaryDictionaryReader.cs : fix utf16 array on getting its
	  length. Report correct length (since BinaryReader is directly used
	  it makes no sense to incompletely keep track of position in Source).

	* XmlBinaryDictionaryReaderTest.cs : added test for utf16 chars.


svn path=/trunk/mcs/; revision=134388
Atsushi Eno 16 роки тому
батько
коміт
65586c8d12

+ 6 - 0
mcs/class/System.Runtime.Serialization/System.Xml/ChangeLog

@@ -1,3 +1,9 @@
+2009-05-19  Atsushi Enomoto  <[email protected]>
+
+	* XmlBinaryDictionaryReader.cs : fix utf16 array on getting its
+	  length. Report correct length (since BinaryReader is directly used
+	  it makes no sense to incompletely keep track of position in Source).
+
 2009-05-19  Atsushi Enomoto  <[email protected]>
 
 	* XmlBinaryDictionaryReader.cs : support reader quotas.

+ 9 - 16
mcs/class/System.Runtime.Serialization/System.Xml/XmlBinaryDictionaryReader.cs

@@ -55,35 +55,29 @@ namespace System.Xml
 
 		internal class StreamSource : ISource
 		{
-			BinaryReader stream;
-			int position;
+			BinaryReader reader;
 
 			public StreamSource (Stream stream)
 			{
-				this.stream = new BinaryReader (stream);
+				this.reader = new BinaryReader (stream);
 			}
 
 			public int Position {
-				get { return position - 1; }
+				get { return (int) reader.BaseStream.Position; }
 			}
 
 			public BinaryReader Reader {
-				get { return stream; }
+				get { return reader; }
 			}
 
 			public int ReadByte ()
 			{
-				if (stream.PeekChar () < 0)
-					return -1;
-				position++;
-				return stream.ReadByte ();
+				return reader.ReadByte ();
 			}
 
 			public int Read (byte [] data, int offset, int count)
 			{
-				int ret = stream.Read (data, offset, count);
-				position += ret;
-				return ret;
+				return reader.Read (data, offset, count);
 			}
 		}
 
@@ -214,7 +208,6 @@ namespace System.Xml
 
 			XmlBinaryDictionaryReader owner;
 			public int ValueIndex;
-			public int NSIndex;
 
 			public override void Reset ()
 			{
@@ -944,8 +937,8 @@ namespace System.Xml
 			case BF.Utf16_32:
 				Encoding enc = ident <= BF.Chars32 ? Encoding.UTF8 : Encoding.Unicode;
 				size =
-					(ident == BF.Chars8) ? source.Reader.ReadByte () :
-					(ident == BF.Chars16) ? source.Reader.ReadUInt16 () :
+					(ident == BF.Chars8 || ident == BF.Utf16_8) ? source.Reader.ReadByte () :
+					(ident == BF.Chars16 || ident == BF.Utf16_16) ? source.Reader.ReadUInt16 () :
 					source.Reader.ReadInt32 ();
 				byte [] bytes = Alloc (size);
 				source.Reader.Read (bytes, 0, size);
@@ -972,7 +965,7 @@ namespace System.Xml
 		byte [] Alloc (int size)
 		{
 			if (size > quota.MaxStringContentLength || size < 0)
-				throw new XmlException (String.Format ("Text content buffer exceeds the quota limitation. {0} bytes and should be less than {1} bytes", size, quota.MaxStringContentLength));
+				throw new XmlException (String.Format ("Text content buffer exceeds the quota limitation at {2}. {0} bytes and should be less than {1} bytes", size, quota.MaxStringContentLength, source.Position));
 			return new byte [size];
 		}
 

+ 4 - 0
mcs/class/System.Runtime.Serialization/Test/System.Xml/ChangeLog

@@ -1,3 +1,7 @@
+2009-05-19  Atsushi Enomoto  <[email protected]>
+
+	* XmlBinaryDictionaryReaderTest.cs : added test for utf16 chars.
+
 2009-05-14  Atsushi Enomoto  <[email protected]>
 
 	* XmlBinaryWriterSession.cs : added test to verify that session is

+ 37 - 0
mcs/class/System.Runtime.Serialization/Test/System.Xml/XmlBinaryDictionaryReaderTest.cs

@@ -401,5 +401,42 @@ namespace MonoTests.System.Xml
 			0x03, 0x40, 2, 0x65, 0x6C, 0x01,
 			0x8D, 3, 0, 0, 0, 0, 6, 0, 0, 0, 8, 0, 0, 0,
 			};
+
+		[Test]
+		public void ReadUtf16Array ()
+		{
+			// example of SOAP fault returned by .NET.
+			var buffer = new byte [] {
+0x56,0x02,0x0B,0x01,0x73,0x04,0x0B,0x01,0x61,0x06,0x56,0x08,0x44,0x0A,0x1E,0x00,
+0x82,0x99,0x2F,0x68,0x74,0x74,0x70,0x3A,0x2F,0x2F,0x77,0x77,0x77,0x2E,0x77,0x33,
+0x2E,0x6F,0x72,0x67,0x2F,0x32,0x30,0x30,0x35,0x2F,0x30,0x38,0x2F,0x61,0x64,0x64,
+0x72,0x65,0x73,0x73,0x69,0x6E,0x67,0x2F,0x73,0x6F,0x61,0x70,0x2F,0x66,0x61,0x75,
+0x6C,0x74,0x44,0x0C,0x1E,0x00,0x82,0xAB,0x14,0x01,0x56,0x0E,0x56,0x86,0x01,0x56,
+0x8E,0x01,0x56,0x9A,0x01,0x98,0x01,0x73,0x98,0x01,0x3A,0x99,0x06,0x53,0x65,0x6E,
+0x64,0x65,0x72,0x56,0x9C,0x01,0x56,0x9A,0x01,0x98,0x01,0x61,0x98,0x01,0x3A,0x99,
+0x16,0x44,0x65,0x73,0x74,0x69,0x6E,0x61,0x74,0x69,0x6F,0x6E,0x55,0x6E,0x72,0x65,
+0x61,0x63,0x68,0x61,0x62,0x6C,0x65,0x01,0x01,0x56,0x90,0x01,0x56,0x92,0x01,0x05,
+0x03,0x78,0x6D,0x6C,0x04,0x6C,0x61,0x6E,0x67,0x98,0x05,0x6A,0x61,0x2D,0x4A,0x50,
+0xB7,0xEA,0x45,0x00,0x6E,0x00,0x64,0x00,0x70,0x00,0x6F,0x00,0x69,0x00,0x6E,0x00,
+0x74,0x00,0x44,0x00,0x69,0x00,0x73,0x00,0x70,0x00,0x61,0x00,0x74,0x00,0x63,0x00,
+0x68,0x00,0x65,0x00,0x72,0x00,0x20,0x00,0x67,0x30,0x20,0x00,0x41,0x00,0x64,0x00,
+0x64,0x00,0x72,0x00,0x65,0x00,0x73,0x00,0x73,0x00,0x46,0x00,0x69,0x00,0x6C,0x00,
+0x74,0x00,0x65,0x00,0x72,0x00,0x20,0x00,0x4C,0x30,0x00,0x4E,0xF4,0x81,0x57,0x30,
+0x66,0x30,0x44,0x30,0x6A,0x30,0x44,0x30,0x5F,0x30,0x81,0x30,0x01,0x30,0x54,0x00,
+0x6F,0x00,0x20,0x00,0x27,0x00,0x27,0x00,0x20,0x00,0x92,0x30,0x2B,0x54,0x80,0x30,
+0xE1,0x30,0xC3,0x30,0xBB,0x30,0xFC,0x30,0xB8,0x30,0x92,0x30,0xD7,0x53,0xE1,0x4F,
+0x74,0x50,0x67,0x30,0xE6,0x51,0x06,0x74,0x67,0x30,0x4D,0x30,0x7E,0x30,0x5B,0x30,
+0x93,0x30,0x02,0x30,0x01,0x90,0xE1,0x4F,0x74,0x50,0x68,0x30,0xD7,0x53,0xE1,0x4F,
+0x74,0x50,0x6E,0x30,0x20,0x00,0x45,0x00,0x6E,0x00,0x64,0x00,0x70,0x00,0x6F,0x00,
+0x69,0x00,0x6E,0x00,0x74,0x00,0x41,0x00,0x64,0x00,0x64,0x00,0x72,0x00,0x65,0x00,
+0x73,0x00,0x73,0x00,0x20,0x00,0x4C,0x30,0x00,0x4E,0xF4,0x81,0x57,0x30,0x66,0x30,
+0x44,0x30,0x8B,0x30,0x53,0x30,0x68,0x30,0x92,0x30,0xBA,0x78,0x8D,0x8A,0x57,0x30,
+0x66,0x30,0x4F,0x30,0x60,0x30,0x55,0x30,0x44,0x30,0x02,0x30,0x01,0x01,0x01,0x01};
+			var dic = new XmlDictionary ();
+			for (int i = 0; i < 128; i++) dic.Add ("s" + i);
+			var xr = XmlDictionaryReader.CreateBinaryReader (new MemoryStream (buffer), dic, new XmlDictionaryReaderQuotas ());
+			while (!xr.EOF)
+				xr.Read ();
+		}
 	}
 }