[Issue 15586] New: std.utf.toUTF8() segfaults when fed an invalid dchar

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Wed Jan 20 11:38:23 PST 2016


https://issues.dlang.org/show_bug.cgi?id=15586

          Issue ID: 15586
           Summary: std.utf.toUTF8() segfaults when fed an invalid dchar
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: phobos
          Assignee: nobody at puremagic.com
          Reporter: thomas.bockman at gmail.com

Repro:

void main()
{
    import std.utf : toUTF8;
    char[4] buf = void;
    auto b = toUTF8(buf, cast(dchar)0x110000);

    import std.stdio;
    writeln(b);
}

Cause:

toUTF8() asserts that invalid dchars just *don't exist*. It then proceeds to
return *nothing at all* when fed one, which violates memory safety.

Because of https://issues.dlang.org/show_bug.cgi?id=15585 the compiler may
optimize away attempts to fix this entirely.

--


More information about the Digitalmars-d-bugs mailing list