[Issue 22867] New: std.utf.decode changes offset despite error.

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Mar 10 08:11:35 UTC 2022


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

          Issue ID: 22867
           Summary: std.utf.decode changes offset despite error.
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: phobos
          Assignee: nobody at puremagic.com
          Reporter: default_357-line at yahoo.de

The documentation for `decode` states:

"If the code point is not well-formed, then a UTFException is thrown and index
remains unchanged."

However, fuzzing with /dev/urandom found that this

import std.conv;
import std.format;
import std.utf;

void main() {
    string data = hexString!"f787a598";
    size_t offset = 0;
    try
    {
        data.decode(offset);
    } catch (UTFException ex) {
        assert(offset == 0, "offset changed to %s despite exception
%s".format(offset, ex.msg));
    }
}

fails.

--


More information about the Digitalmars-d-bugs mailing list