D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 22867 - std.utf.decode changes offset despite error.
Summary: std.utf.decode changes offset despite error.
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: x86_64 Linux
: P1 normal
Assignee: No Owner
URL:
Keywords: pull
Depends on:
Blocks:
 
Reported: 2022-03-10 08:11 UTC by FeepingCreature
Modified: 2022-03-10 14:38 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description FeepingCreature 2022-03-10 08:11:35 UTC
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.
Comment 1 Dlang Bot 2022-03-10 12:09:00 UTC
@aG0aep6G created dlang/phobos pull request #8408 "fix issue 22867 - std.utf.decode changes offset despite error." fixing this issue:

- fix issue 22867 - std.utf.decode changes offset despite error.

https://github.com/dlang/phobos/pull/8408
Comment 2 Dlang Bot 2022-03-10 14:38:58 UTC
dlang/phobos pull request #8408 "fix issue 22867 - std.utf.decode changes offset despite error." was merged into master:

- 3a97e4a9e97debb6c6d5c7460a52efd3e5d9250c by aG0aep6G:
  fix issue 22867 - std.utf.decode changes offset despite error.

https://github.com/dlang/phobos/pull/8408