diff --git a/library/src/main/java/com/bumptech/glide/util/ByteBufferUtil.java b/library/src/main/java/com/bumptech/glide/util/ByteBufferUtil.java index 7889015757..6b1b3452c2 100644 --- a/library/src/main/java/com/bumptech/glide/util/ByteBufferUtil.java +++ b/library/src/main/java/com/bumptech/glide/util/ByteBufferUtil.java @@ -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 {