6934977: (bf) MappedByteBuffer.load can SIGBUS if file is truncated
Alan Bateman
Alan.Bateman at oracle.com
Wed Jul 21 07:36:37 PDT 2010
If the file underlying a mapped byte buffer is truncated then it's
possible that invoking the MappedByteBuffer's load method will SIGBUS.
The reason is that the load touches each page in a native method and the
VM's handler cannot deal with the fault. A second and related issue
(6799037) is that same native code is reading an int from each page
without taking alignment into consideration or the possibility that it
might read beyond the end of the mapping. Yet another issue, is that
isLoaded fails with an IOException for the case that the mapping doesn't
start on a multiple of the page size. The load method has a similar
problem but it doesn't throw IOException because it is ignoring the
return value from madvise(3C).
The webrev with the proposed changes to fix these issues is here:
http://cr.openjdk.java.net/~alanb/6934977/webrev
The main change is that load is changed to touch the pages via Unsafe
and so uses the existing handler.
-Alan.
More information about the nio-dev
mailing list