Bug 14136 – std.uni.utfMatcher breaks @safety

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-02-07T00:44:00Z
Last change time
2016-10-01T11:47:33Z
Keywords
safe
Assigned to
nobody
Creator
code

Comments

Comment #0 by code — 2015-02-07T00:44:31Z
--- 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 by bugzilla — 2016-06-07T12:06:57Z
Comment #2 by john.loughran.colvin — 2016-06-07T14:06:23Z
I don't think match calls empty anywhere except inside an assert.
Comment #3 by code — 2016-06-07T17:53:56Z
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 by github-bugzilla — 2016-06-08T15:26:24Z
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 by code — 2016-06-08T22:09:41Z
As pointed out before, the patch actually only fixed a part of the problem, but the issue was still auto-closed.
Comment #6 by github-bugzilla — 2016-10-01T11:45:26Z
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