Skip to content

Commit

Permalink
Fix error mapping files over Integer.MAX_VALUE in length.
Browse files Browse the repository at this point in the history
Fixes #2240.
  • Loading branch information
sjudd committed Aug 14, 2017
1 parent 06aced3 commit 8fac123
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,14 @@ public static ByteBuffer fromFile(File file) throws IOException {
RandomAccessFile raf = null;
FileChannel channel = null;
try {
long fileLength = file.length();
// See #2240.
if (fileLength > Integer.MAX_VALUE) {
throw new IOException("File too large to map into memory");
}
raf = new RandomAccessFile(file, "r");
channel = raf.getChannel();
return channel.map(FileChannel.MapMode.READ_ONLY, 0, file.length()).load();
return channel.map(FileChannel.MapMode.READ_ONLY, 0, fileLength).load();
} finally {
if (channel != null) {
try {
Expand Down

0 comments on commit 8fac123

Please sign in to comment.