bumptech/glide · error · IOException

File too large to map into memory

Error message

File too large to map into memory

What it means

Thrown by ByteBufferUtil.fromFile(File) when file.length() exceeds Integer.MAX_VALUE (~2 GiB). The method memory-maps the file into a java.nio.ByteBuffer, which is indexed by int and therefore cannot address more than 2^31-1 bytes. This guard prevents a 2GB+ file from producing a bogus partial mapping.

Source

Thrown at library/src/main/java/com/bumptech/glide/util/ByteBufferUtil.java:37

@SuppressWarnings({"unused", "WeakerAccess"}) // Public API
public final class ByteBufferUtil {
  // 16 Kb
  private static final int BUFFER_SIZE = 16384;
  private static final AtomicReference<byte[]> BUFFER_REF = new AtomicReference<>();

  private ByteBufferUtil() {
    // Utility class.
  }

  @NonNull
  public static ByteBuffer fromFile(@NonNull 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");
      }
      // 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();
    } finally {
      if (channel != null) {
        try {
          channel.close();
        } catch (IOException e) {
          // Ignored.
        }
      }
      if (raf != null) {

View on GitHub (pinned to eb14a895d8)

Solutions

  1. Avoid memory-mapping files > 2GB; stream them instead (use an InputStream-based model/decoder rather than asFile().load(file))
  2. Reduce source file size (transcode/downscale the media before handing to Glide)
  3. For video, use VideoView/ExoPlayer rather than Glide
  4. Pre-check file.length() and skip or surface a user-facing 'file too large' message

Example fix

// before
Glide.with(ctx).asFile().load(hugeFile).into(target) // > 2 GiB

// after - guard before loading
if (hugeFile.length() > Integer.MAX_VALUE) {
  showError("File too large to load")
} else {
  Glide.with(ctx).asFile().load(hugeFile).into(target)
}
Defensive patterns

Strategy: validation

Validate before calling

fun File.isMappable(): Boolean = exists() && length() in 1..Integer.MAX_VALUE.toLong()

if (file.isMappable()) {
  Glide.with(ctx).asFile().load(file).into(target)
} else {
  showTooLargeError()
}

Prevention

When it happens

Trigger: Loading a local file > 2GB via any Glide path that funnels through ByteBufferUtil.fromFile (e.g. asFile().load(file), or a File model with certain decoders). Also triggered by FileChannel.map on huge media files shared into the app.

Common situations: Loading very large video files or archives; on devices where the user picks a >2GB file via SAF/Storage Access Framework; misconfigured cache that grew a single cache entry beyond 2GB.

Related errors


AI-assisted analysis of bumptech/glide@eb14a895d8 (2026-08-14). Data as JSON: /api/errors/084dbb48b2e2f725. Report an issue: GitHub.