Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

System.Text.Decoder throws ArgumentOutOfRangeException when it should no... #580

Closed
wants to merge 1 commit into from

Conversation

martinpotter
Copy link
Contributor

...t. Fixes Bug #10789

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

… not. Fixes Bug mono#10789

Similar to previously reported bug mono#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."
@marek-safar
Copy link
Member

Could you re-submit the request, there is conflict probably in test files

@martinpotter
Copy link
Contributor Author

Request resubmitted, #584

lambdageek added a commit that referenced this pull request Apr 25, 2017
* Check strong names on a couple more codepaths during assembly loading.  Fixes [bugzilla #580](https://bugzilla.xamarin.com/show_bug.cgi?id=580) and [bugzilla #55436](https://bugzilla.xamarin.com/show_bug.cgi?id=55436)
* Add `--apply-bindings=FILE` option.  Allows us to specify a configuration file for assembly binding redirections when AOTing.
* Use the above flag when AOTing `System.ReflectionMetadata.dll` to pick up `csc.exe.config`
* Add all the Facades to the `framework_assemblies` list in the runtime.  Facade and non-Facade framework assemblies behave differently:
  * for Facades, don't do any version remapping, and any version is okay.
  * for non-Facades, consult the version map to remap depdending on the --runtime used.
lambdageek added a commit that referenced this pull request Apr 26, 2017
* Check strong names on a couple more codepaths during assembly loading.  Fixes [bugzilla #580](https://bugzilla.xamarin.com/show_bug.cgi?id=580) and [bugzilla #55436](https://bugzilla.xamarin.com/show_bug.cgi?id=55436)
* Add `--apply-bindings=FILE` option.  Allows us to specify a configuration file for assembly binding redirections when AOTing.
* Use the above flag when AOTing `System.ReflectionMetadata.dll` to pick up `csc.exe.config`
* Add all the Facades to the `framework_assemblies` list in the runtime.  Facade and non-Facade framework assemblies behave differently:
  * for Facades, don't do any version remapping, and any version is okay.
  * for non-Facades, consult the version map to remap depdending on the --runtime used.
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
* Check strong names on a couple more codepaths during assembly loading.  Fixes [bugzilla mono/mono#580](https://bugzilla.xamarin.com/show_bug.cgi?id=580) and [bugzilla mono/mono#55436](https://bugzilla.xamarin.com/show_bug.cgi?id=55436)
* Add `--apply-bindings=FILE` option.  Allows us to specify a configuration file for assembly binding redirections when AOTing.
* Use the above flag when AOTing `System.ReflectionMetadata.dll` to pick up `csc.exe.config`
* Add all the Facades to the `framework_assemblies` list in the runtime.  Facade and non-Facade framework assemblies behave differently:
  * for Facades, don't do any version remapping, and any version is okay.
  * for non-Facades, consult the version map to remap depdending on the --runtime used.

Commit migrated from mono/mono@25bcd22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants