[Mono-bugs] [Bug 415628] Bad UTF-8 sequences result in a crash

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Mon Jan 26 16:53:43 EST 2009


https://bugzilla.novell.com/show_bug.cgi?id=415628

User jlarimer at gmail.com added comment
https://bugzilla.novell.com/show_bug.cgi?id=415628#c8


Jon Larimer <jlarimer at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jlarimer at gmail.com




--- Comment #8 from Jon Larimer <jlarimer at gmail.com>  2009-01-26 14:53:40 MST ---
I also ran into this issue. Here is a test case that demonstrates the problem I
see:

-----8<-------8<------------

using System;
using System.IO;
using System.Text;

public class Test {
    public static void Main() {
        byte[] test = new byte[] { 0xe0, 0x2b, 0xf7, 0x5e, 0x91, 0x2a,
            0xd0, 0x4d, 0x8b, 0xda, 0x7e, 0x60, 0xed, 0xbb, 0xba, 0x57 };

        char[] chars = new char[20];

        for(int i=1; i<=test.Length; i++) {
            Console.WriteLine("{0} {1}",
                Encoding.UTF8.GetCharCount(test, 0, i),
                Encoding.UTF8.GetChars(test, 0, i, chars, 0));
        }
    }
}

-----8<-------8<------------

The problem is that GetCharCount() returns a shorter length than is needed by
GetChars(). The output of this on Mono (r123654) compiled with gmcs is:

1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
10 10
11 11
12 12
13 13
14 14
13 15
14 16

The expected output (from MS.NET) is:

1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
10 10
11 11
12 12
13 13
13 13
14 14
15 15

----------

I ran into this because System.DirectoryServices.DirectorySearcher is calling
LdapAttribute.StringValueArray to retrieve some values from LDAP, and it's
choking when trying to UTF8 decode a GUID stored in binary format, which is not
UTF8 encoding. I'll open a separate bug for that.

-- 
Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.


More information about the mono-bugs mailing list