Issue 15013 - std.mmfile module produces bus error at certain conditions
Summary: std.mmfile module produces bus error at certain conditions
Status: REOPENED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All All
: P3 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-09-04 21:44 UTC by Sergei Degtiarev
Modified: 2024-12-01 16:25 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 Sergei Degtiarev 2015-09-04 21:44:03 UTC
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];
}
Comment 1 Boris Carvajal 2019-12-16 22:57:49 UTC
Still happens on Linux you can check it on run.dlang.io.
On Windows CreateFileMapping fails and the program throws.
Comment 2 berni44 2019-12-17 06:10:39 UTC
(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.
Comment 3 dlangBugzillaToGithub 2024-12-01 16:25:04 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/phobos/issues/10140

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB