Bug 42887 - Encoding iso-8859-1 throws IndexOutOfRangeException for Unicode surrogate pairs
Summary: Encoding iso-8859-1 throws IndexOutOfRangeException for Unicode surrogate pairs
Status: VERIFIED FIXED
Alias: None
Product: Class Libraries
Classification: Mono
Component: System ()
Version: 4.4.0 (C7)
Hardware: All Linux
: --- normal
Target Milestone: 4.6.0 (C8)
Assignee: Alexander Köplinger [MSFT]
URL:
Depends on:
Blocks:
 
Reported: 2016-07-28 14:51 UTC by Lukas Matyska
Modified: 2016-09-01 06:07 UTC (History)
3 users (show)

Tags:
Is this bug a regression?: Yes
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
VERIFIED FIXED

Description Lukas Matyska 2016-07-28 14:51:31 UTC
Description of Problem:
The IndexOutOfRangeException is thrown when calling:
  Encoding.GetEncoding("iso-8859-1").GetBytes(input)
where input contains Unicode surrogate pair, such as smiley.

Steps to reproduce the problem:
1. call this Encoding.GetEncoding("iso-8859-1").GetBytes("\ud83d\ude0a ");


Actual Results:
IndexOutOfRangeException is thrown

Expected Results:
No exception is thrown; three bytes are returned.

How often does this happen? 
Always.
Comment 1 Lukas Matyska 2016-07-28 14:57:38 UTC
This BUG is new to Mono version 4.

I have tested this on Mono 2.10.8.1 and 3.2.8 (Debian) without exception.
The exception was risen on Mono 4.4.1.
Comment 2 Alexander Köplinger [MSFT] 2016-08-30 18:31:44 UTC
Thank you for the bug report!

I implemented a fix in this pull request: https://github.com/mono/mono/pull/3489
Comment 3 Alexander Köplinger [MSFT] 2016-08-31 22:48:19 UTC
This was merged to mono master/4b5eace32dc2c6353425f9ee75299b7fc3e43e02 and mono-4.6.0-branch/50e81ed6e587222f9af6b9d372ea7f798e145236