Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

std.mmfile module produces bus error at certain conditions #10140

Open
dlangBugzillaToGithub opened this issue Sep 4, 2015 · 2 comments
Open

Comments

@dlangBugzillaToGithub
Copy link

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];
}
@dlangBugzillaToGithub
Copy link
Author

boris2.9 commented on 2019-12-16T22:57:49Z

Still happens on Linux you can check it on run.dlang.io.
On Windows CreateFileMapping fails and the program throws.

@dlangBugzillaToGithub
Copy link
Author

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.

@LightBender LightBender removed the P3 label Dec 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants