Bug 42887

Summary: Encoding iso-8859-1 throws IndexOutOfRangeException for Unicode surrogate pairs
Product: [Mono] Class Libraries Reporter: Lukas Matyska <matyskal>
Component: SystemAssignee: Alexander Köplinger [MSFT] <alkpli>
Severity: normal CC: masafa, mono-bugs+mono, shrutis
Priority: ---    
Version: 4.4.0 (C7)   
Target Milestone: 4.6.0 (C8)   
Hardware: All   
OS: Linux   
Tags: Is this bug a regression?: Yes
Last known good build:

Description Lukas Matyska 2016-07-28 14:51:31 UTC
Description of Problem:
The IndexOutOfRangeException is thrown when calling:
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? 
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 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