oxc-project/oxc · error · std::io::Error

File is larger than `isize::MAX` bytes

Error message

File is larger than `isize::MAX` bytes

What it means

Guard in read_to_arena_bytes_known_size: a pre-allocation of the file into the arena requires a slice, and Rust slice lengths cannot exceed isize::MAX. isize::try_from(u64 size) failed, meaning the stat'd file size exceeds the addressable limit, so the read is aborted before attempting an impossible allocation.

Source

Thrown at crates/oxc_linter/src/utils/mod.rs:209

    } else {
        read_to_arena_bytes_unknown_size(file, allocator)
    }?;

    // Convert to `&str`, checking contents is valid UTF-8
    simdutf8::basic::from_utf8(bytes).map_err(|_| {
        io::Error::new(io::ErrorKind::InvalidData, "stream did not contain valid UTF-8")
    })
}

/// Read contents of file directly into arena.
fn read_to_arena_bytes_known_size(
    file: File,
    size: u64,
    allocator: &Allocator,
) -> io::Result<&[u8]> {
    // Check file is not larger than `isize::MAX` bytes (the max size of an allocation)
    let Ok(size) = isize::try_from(size) else {
        return Err(io::Error::new(
            io::ErrorKind::InvalidData,
            "File is larger than `isize::MAX` bytes",
        ));
    };
    #[expect(clippy::cast_sign_loss)]
    let mut size = size as usize;

    // Allocate space for string in allocator.
    // SAFETY: We checked above that `size <= isize::MAX`. `&str` has no alignment requirements.
    let layout = unsafe { Layout::from_size_align_unchecked(size, 1) };
    let ptr = allocator.alloc_layout(layout);

    // Read contents of file into allocated space.
    //
    // * Create a `Vec` which pretends to own the allocation we just created in arena.
    // * Wrap the `Vec` in `ManuallyDrop`, so it doesn't free the memory at end of the block,
    //   or if there's a panic during reading.
    // * Use `File::take` to obtain a reader which yields no more than `size` bytes.

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Reject or skip the oversized file with a clear user-facing error
  2. Read the file in chunks or memory-map it instead of one arena allocation
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/oxc_linter/src/utils/mod.rs:209 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20). Data as JSON: /api/errors/744071867c05fdba. Report an issue: GitHub.