Skip to content

Commit

Permalink
Make ByteBufferUtil::fromFile fail if file cannot be mmap'd.
Browse files Browse the repository at this point in the history
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=172750122
  • Loading branch information
pkorth authored and sjudd committed Oct 19, 2017
1 parent f77a02c commit cbe9f42
Showing 1 changed file with 5 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ public static ByteBuffer fromFile(File file) throws IOException {
if (fileLength > Integer.MAX_VALUE) {
throw new IOException("File too large to map into memory");
}
// See b/67710449.
if (fileLength == 0) {
throw new IOException("File unsuitable for memory mapping");
}

raf = new RandomAccessFile(file, "r");
channel = raf.getChannel();
return channel.map(FileChannel.MapMode.READ_ONLY, 0, fileLength).load();
Expand Down

0 comments on commit cbe9f42

Please sign in to comment.