Skip to content

No file size limit enforced before fetchFile() loads entire video into WASM heap - large files crash the browser tab #1704

Description

@anshul23102

Problem

In src/lib/ffmpeg.ts, the exportVideo function calls:

await ffmpeg.writeFile(inputName, await fetchFile(file), { signal });

fetchFile(file) reads the entire File object into a Uint8Array in
JavaScript memory, which is then copied into the WASM heap. There is no
maximum file size check before this happens.

A user who selects a large video file (e.g. a 4K raw recording of several GB)
will trigger an allocation that exhausts the browser's WASM heap (typically
limited to 2-4GB), causing the browser tab to crash with an out-of-memory
error and no user-friendly message.

This is especially problematic on mobile devices with limited RAM, where even
files over 500MB can cause crashes.

Steps to Reproduce

  1. Select a video file larger than 1GB.
  2. Click Export.
  3. Observe: the browser tab crashes or hangs indefinitely with no error shown.

Suggested Fix

  1. Add a file size check before calling fetchFile:
    const MAX_FILE_SIZE_BYTES = 500 * 1024 * 1024; // 500 MB
    if (file.size > MAX_FILE_SIZE_BYTES) {
      throw new Error("File too large. Maximum supported size is 500 MB.");
    }
  2. Display the limit in the file picker UI so users know before selecting.
  3. For files near the limit, show a warning with an estimate of required RAM.
  4. Document the supported size range in the README.

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions