Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mcs/class/corlib/System.Text/Decoder.cs9
-rw-r--r--mcs/class/corlib/System.Text/UTF8Encoding.cs2
-rw-r--r--mcs/class/corlib/Test/System.Text/DecoderTest.cs17
-rw-r--r--mcs/class/corlib/Test/System.Text/UTF8EncodingTest.cs22
4 files changed, 46 insertions, 4 deletions
diff --git a/mcs/class/corlib/System.Text/Decoder.cs b/mcs/class/corlib/System.Text/Decoder.cs
index fe715c33796..cf2e6f23efc 100644
--- a/mcs/class/corlib/System.Text/Decoder.cs
+++ b/mcs/class/corlib/System.Text/Decoder.cs
@@ -149,7 +149,10 @@ public abstract class Decoder
out int bytesUsed, out int charsUsed, out bool completed)
{
CheckArguments (bytes, byteIndex, byteCount);
- CheckArguments (chars, charIndex);
+ if (chars == null)
+ throw new ArgumentNullException ("chars");
+ if (charIndex < 0)
+ throw new ArgumentOutOfRangeException ("charIndex");
if (charCount < 0 || chars.Length < charIndex + charCount)
throw new ArgumentOutOfRangeException ("charCount");
@@ -169,7 +172,7 @@ public abstract class Decoder
{
if (chars == null)
throw new ArgumentNullException ("chars");
- if (charIndex < 0 || chars.Length <= charIndex)
+ if (charIndex < 0 || chars.Length < charIndex)
throw new ArgumentOutOfRangeException ("charIndex");
}
@@ -177,7 +180,7 @@ public abstract class Decoder
{
if (bytes == null)
throw new ArgumentNullException ("bytes");
- if (byteIndex < 0 || bytes.Length <= byteIndex)
+ if (byteIndex < 0)
throw new ArgumentOutOfRangeException ("byteIndex");
if (byteCount < 0 || bytes.Length < byteIndex + byteCount)
throw new ArgumentOutOfRangeException ("byteCount");
diff --git a/mcs/class/corlib/System.Text/UTF8Encoding.cs b/mcs/class/corlib/System.Text/UTF8Encoding.cs
index 3a1c2bd680f..bdd80e8a626 100644
--- a/mcs/class/corlib/System.Text/UTF8Encoding.cs
+++ b/mcs/class/corlib/System.Text/UTF8Encoding.cs
@@ -663,7 +663,7 @@ fail_no_space:
throw new ArgumentOutOfRangeException ("charIndex", _("ArgRange_Array"));
}
- if (charIndex == chars.Length)
+ if (charIndex == chars.Length && byteCount == 0)
return 0;
fixed (char* cptr = chars) {
diff --git a/mcs/class/corlib/Test/System.Text/DecoderTest.cs b/mcs/class/corlib/Test/System.Text/DecoderTest.cs
index 3da0846360b..6cf0306d823 100644
--- a/mcs/class/corlib/Test/System.Text/DecoderTest.cs
+++ b/mcs/class/corlib/Test/System.Text/DecoderTest.cs
@@ -98,5 +98,22 @@ namespace MonoTests.System.Text
}
}
#endif
+
+ [Test]
+ public void Bug10789 ()
+ {
+ byte[] bytes = new byte[100];
+ char[] chars = new char[100];
+
+ Decoder conv = Encoding.UTF8.GetDecoder ();
+ int charsUsed, bytesUsed;
+ bool completed;
+
+ conv.Convert (bytes, 0, 0, chars, 100, 0, false, out bytesUsed, out charsUsed, out completed);
+
+ Assert.IsTrue (completed, "#1");
+ Assert.AreEqual (0, charsUsed, "#2");
+ Assert.AreEqual (0, bytesUsed, "#3");
+ }
}
}
diff --git a/mcs/class/corlib/Test/System.Text/UTF8EncodingTest.cs b/mcs/class/corlib/Test/System.Text/UTF8EncodingTest.cs
index 022e8d7db7c..1f53af7e3eb 100644
--- a/mcs/class/corlib/Test/System.Text/UTF8EncodingTest.cs
+++ b/mcs/class/corlib/Test/System.Text/UTF8EncodingTest.cs
@@ -1174,5 +1174,27 @@ namespace MonoTests.System.Text
Encoding.UTF8.GetDecoder ().GetChars (bytes, 0, 4096, chars, 9, false);
}
+
+ [Test]
+ public void Bug10789()
+ {
+ byte[] bytes = new byte[4096];
+ char[] chars = new char[10];
+
+ try {
+ Encoding.UTF8.GetDecoder ().GetChars (bytes, 0, 1, chars, 10, false);
+ Assert.Fail ("ArgumentException is expected #1");
+ } catch (ArgumentException) {
+ }
+
+ try {
+ Encoding.UTF8.GetDecoder ().GetChars (bytes, 0, 1, chars, 11, false);
+ Assert.Fail ("ArgumentOutOfRangeException is expected #2");
+ } catch (ArgumentOutOfRangeException) {
+ }
+
+ int charactersWritten = Encoding.UTF8.GetDecoder ().GetChars (bytes, 0, 0, chars, 10, false);
+ Assert.AreEqual (0, charactersWritten, "#3");
+ }
}
}