Similar to previously reported bug #6404, according to the documentation at http://msdn.microsoft.com/en-us/library/h6w985hz.aspx, System.Text.Encoder throws ArgumentOutOfRangeExceptions when it should not. From the documentation, an ArgumentOutOfRangeException should be thrown when:
charIndex, charCount, byteIndex, or byteCount is less than zero.
-or-
The length of chars - charIndex is less than charCount.
-or-
The length of bytes - byteIndex is less than byteCount.
To reproduce, run the following code:
int charsUsed, bytesUsed;
bool completed;
byte[] bytes = new byte[4096];
char[] chars = new char[4096];
System.Text.Encoding.UTF8.GetDecoder().Convert(bytes, 0, 0, chars, 4096, 0, false, out bytesUsed, out charsUsed, out completed);
Expected:
The code runs, charsUsed equals zero, bytesUsed equals zero and completed is true.
Actual:
Mono throws an ArgumentOutOfRangeException for charIndex.
There are also other behavioral differences between Mono and Microsoft's implementation for the GetChars(Byte[], Int32, Int32, Char[], Int32, Boolean) method, such as:
byte[] bytes = new byte[4096];
char[] chars = new char[10];
int charactersWritten = System.Text.Encoding.UTF8.GetDecoder().GetChars(bytes, 0, 0, chars, 10, false);
On Mono, this results in an ArgumentOutOfRangeException for charIndex, where for Microsoft charactersWritten = 0.
Similarly:
byte[] bytes = new byte[4096];
char[] chars = new char[10];
int charactersWritten = System.Text.Encoding.UTF8.GetDecoder().GetChars(bytes, 0, 4096, chars, 10, false);
On Mono, this results in the same ArgumentOutOfRangeException for charIndex, where Microsoft throws and ArgumentException. since "chars does not have enough capacity from charIndex to the end of the array to accommodate the resulting characters."
2009-01-13 Jb Evain <[email protected]>
* Encoding.cs: when creating a ForwardingEncoder or a
ForwardingDecoder, don't crash if the Encoding doesn't
provide an EncoderFallback or a DecoderFallback.
in Test/System.Text:
2009-01-13 Jb Evain <[email protected]>
* EncoderTest.cs: Make sure we can get an encoder for a custom
encoding.
* DecoderTest.cs: ditto.
svn path=/trunk/mcs/; revision=123196
* Encoder.cs, Decoder.cs : implemented Convert(). Also added argument
check in some methods.
* EncoderTest.cs, DecoderTest.cs : new tests, for Convert().
* corlib_test.dll.sources: added EncoderTest.cs and DecoderTest.cs.
svn path=/trunk/mcs/; revision=58819