Issue 14136 - std.uni.utfMatcher breaks @safety
Summary: std.uni.utfMatcher breaks @safety
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All All
: P1 normal
Assignee: No Owner
URL:
Keywords: safe
Depends on:
Blocks:
 
Reported: 2015-02-07 00:44 UTC by David Nadlinger
Modified: 2016-10-01 11:47 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description David Nadlinger 2015-02-07 00:44:31 UTC
---
struct Oops {
pure:
    bool empty() {
        *cast(int*)0xcafebabe = 0xdeadbeef;
        return true;
    }

    Oops save() @property { return this; }
    char front;
    void popFront() {}
    char back;
    void popBack() {}
    ref char opIndex(size_t idx) { return front; }
    enum size_t length = 0;
    alias opDollar = length;
}

void main() @safe {
    import std.uni;
    auto m = utfMatcher!char(unicode.Number);
    Oops o;
    m.match(o);
}
---

Again, the reason is a @trusted template function taking an arbitrary range.

Source permalink (other match variants are affected too): https://github.com/D-Programming-Language/phobos/blob/041db2d8fac2b1cf5169be7188ea537a01f27586/std/uni.d#L4767-L4787

Introduced in https://github.com/D-Programming-Language/phobos/pull/2020.
Comment 1 Walter Bright 2016-06-07 12:06:57 UTC
https://github.com/dlang/phobos/pull/4416
Comment 2 John Colvin 2016-06-07 14:06:23 UTC
I don't think match calls empty anywhere except inside an assert.
Comment 3 David Nadlinger 2016-06-07 17:53:56 UTC
match() is just one of a number of @trusted range functions in that module (see e.g. the declarations immediately surrounding it). This example is just to illustrate that this indeed leads to a real problem with safety.

Careful auditing of the use of @trusted in the module will be required to fully resolve this issue.
Comment 4 github-bugzilla 2016-06-08 15:26:24 UTC
Commits pushed to master at https://github.com/dlang/phobos

https://github.com/dlang/phobos/commit/16099c6ec538b34cc5de97940f509fb0c15c0268
fix
Issue 14136 - std.uni.utfMatcher breaks @safety

https://github.com/dlang/phobos/commit/7792499d9ebfee7b808964b2e492270ead4111f2
Merge pull request #4416 from WalterBright/fix14136

fix Issue 14136 - std.uni.utfMatcher breaks @safety
Comment 5 David Nadlinger 2016-06-08 22:09:41 UTC
As pointed out before, the patch actually only fixed a part of the problem, but the issue was still auto-closed.
Comment 6 github-bugzilla 2016-10-01 11:45:26 UTC
Commits pushed to stable at https://github.com/dlang/phobos

https://github.com/dlang/phobos/commit/16099c6ec538b34cc5de97940f509fb0c15c0268
fix

https://github.com/dlang/phobos/commit/7792499d9ebfee7b808964b2e492270ead4111f2
Merge pull request #4416 from WalterBright/fix14136

fix Issue 14136 - std.uni.utfMatcher breaks @safety