You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
std.MmFile when opens file in read only mode never expands it, even if memory requested is bigger than actual file size.
When the allocated memory is less than one system page, it passes because mmap() allocates shared memory by page. If however, requested size is bigger than one page, any attempt to read from addresses above page size results to BusError.
Code to illustrate:
unittest // issue: read-only file is not extended
{
auto fn=deleteme;
scope(exit) std.file.remove(fn);
/// create new very short file{ File(fn,"w").write("123"); }/** Trying to map more than one page * The file is not resized and only one page is allocated * Now, the last half of the slice has not valid mapping**/auto n=new MmFile(fn, MmFile.Mode.read, 0x1020, null);auto k=cast(int[]) n[];/// Bus error hereauto y=k[$-1];
}
The text was updated successfully, but these errors were encountered:
bugzilla (@WalterBright) commented on 2019-12-17T06:10:39Z
(In reply to Boris Carvajal from comment #1)
> Still happens on Linux you can check it on run.dlang.io.
Meanwhile I can reproduce it locally. Don't know why it worked yesterday.
> On Windows CreateFileMapping fails and the program throws.
It's been marked as a linux bug... I changed this now.
sdegtiarev (@sdegtiarev) reported this on 2015-09-04T21:44:03Z
Transfered from https://issues.dlang.org/show_bug.cgi?id=15013
CC List
Description
std.MmFile when opens file in read only mode never expands it, even if memory requested is bigger than actual file size. When the allocated memory is less than one system page, it passes because mmap() allocates shared memory by page. If however, requested size is bigger than one page, any attempt to read from addresses above page size results to BusError. Code to illustrate: unittest // issue: read-only file is not extended { auto fn=deleteme; scope(exit) std.file.remove(fn); /// create new very short file { File(fn,"w").write("123"); } /** Trying to map more than one page * The file is not resized and only one page is allocated * Now, the last half of the slice has not valid mapping **/ auto n=new MmFile(fn, MmFile.Mode.read, 0x1020, null); auto k=cast(int[]) n[]; /// Bus error here auto y=k[$-1]; }The text was updated successfully, but these errors were encountered: