Skip to content

Commit f01a213

Browse files
committed
Fix Bugzilla 24685 - std.stdio.File.rawRead allows reading raw pointers from files in @safe code
1 parent c00a5ee commit f01a213

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

std/stdio.d

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,6 +1040,9 @@ Throws: `ErrnoException` if the file is not opened or the call to `fread` fails.
10401040
assert(buf == "\r\n\n\r\n");
10411041
}
10421042

1043+
// https://issues.dlang.org/show_bug.cgi?id=24685
1044+
static assert(!__traits(compiles, (File f) @safe { int*[1] bar; f.rawRead(bar[]); }));
1045+
10431046
// https://issues.dlang.org/show_bug.cgi?id=21729
10441047
@system unittest
10451048
{
@@ -4534,6 +4537,13 @@ private auto trustedFwrite(T)(FILE* f, const T[] obj) @trusted
45344537
* Convenience function that forwards to `core.stdc.stdio.fread`
45354538
*/
45364539
private auto trustedFread(T)(FILE* f, T[] obj) @trusted
4540+
if (!imported!"std.traits".hasIndirections!T)
4541+
{
4542+
return fread(obj.ptr, T.sizeof, obj.length, f);
4543+
}
4544+
4545+
private auto trustedFread(T)(FILE* f, T[] obj) @system
4546+
if (imported!"std.traits".hasIndirections!T)
45374547
{
45384548
return fread(obj.ptr, T.sizeof, obj.length, f);
45394549
}

0 commit comments

Comments
 (0)