Bug 15013 – std.mmfile module produces bus error at certain conditions

Status
REOPENED
Severity
normal
Priority
P3
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-09-04T21:44:03Z
Last change time
2024-12-01T16:25:04Z
Assigned to
No Owner
Creator
Sergei Degtiarev
Moved to GitHub: phobos#10140 →

Comments

Comment #0 by sdegtiarev — 2015-09-04T21:44:03Z
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 by boris2.9 — 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.
Comment #2 by bugzilla — 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.
Comment #3 by robert.schadek — 2024-12-01T16:25:04Z
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