www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 15013] New: std.mmfile module produces bus error at certain

https://issues.dlang.org/show_bug.cgi?id=15013

          Issue ID: 15013
           Summary: std.mmfile module produces bus error at certain
                    conditions
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: phobos
          Assignee: nobody puremagic.com
          Reporter: sdegtiarev yahoo.com

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];
}

--
Sep 04 2015