Skip to content

Commit 8fac123

Browse files
committed
Fix error mapping files over Integer.MAX_VALUE in length.
Fixes #2240.
1 parent 06aced3 commit 8fac123

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

library/src/main/java/com/bumptech/glide/util/ByteBufferUtil.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,14 @@ public static ByteBuffer fromFile(File file) throws IOException {
2626
RandomAccessFile raf = null;
2727
FileChannel channel = null;
2828
try {
29+
long fileLength = file.length();
30+
// See #2240.
31+
if (fileLength > Integer.MAX_VALUE) {
32+
throw new IOException("File too large to map into memory");
33+
}
2934
raf = new RandomAccessFile(file, "r");
3035
channel = raf.getChannel();
31-
return channel.map(FileChannel.MapMode.READ_ONLY, 0, file.length()).load();
36+
return channel.map(FileChannel.MapMode.READ_ONLY, 0, fileLength).load();
3237
} finally {
3338
if (channel != null) {
3439
try {

0 commit comments

Comments
 (0)