{"record":{"id":"744071867c05fdba","repo":"oxc-project/oxc","slug":"file-is-larger-than-isize-max-bytes","errorCode":null,"errorMessage":"File is larger than `isize::MAX` bytes","messagePattern":"File is larger than `isize::MAX` bytes","errorType":"exception","errorClass":"std::io::Error","httpStatus":null,"severity":"error","filePath":"crates/oxc_linter/src/utils/mod.rs","lineNumber":209,"sourceCode":"    } else {\n        read_to_arena_bytes_unknown_size(file, allocator)\n    }?;\n\n    // Convert to `&str`, checking contents is valid UTF-8\n    simdutf8::basic::from_utf8(bytes).map_err(|_| {\n        io::Error::new(io::ErrorKind::InvalidData, \"stream did not contain valid UTF-8\")\n    })\n}\n\n/// Read contents of file directly into arena.\nfn read_to_arena_bytes_known_size(\n    file: File,\n    size: u64,\n    allocator: &Allocator,\n) -> io::Result<&[u8]> {\n    // Check file is not larger than `isize::MAX` bytes (the max size of an allocation)\n    let Ok(size) = isize::try_from(size) else {\n        return Err(io::Error::new(\n            io::ErrorKind::InvalidData,\n            \"File is larger than `isize::MAX` bytes\",\n        ));\n    };\n    #[expect(clippy::cast_sign_loss)]\n    let mut size = size as usize;\n\n    // Allocate space for string in allocator.\n    // SAFETY: We checked above that `size <= isize::MAX`. `&str` has no alignment requirements.\n    let layout = unsafe { Layout::from_size_align_unchecked(size, 1) };\n    let ptr = allocator.alloc_layout(layout);\n\n    // Read contents of file into allocated space.\n    //\n    // * Create a `Vec` which pretends to own the allocation we just created in arena.\n    // * Wrap the `Vec` in `ManuallyDrop`, so it doesn't free the memory at end of the block,\n    //   or if there's a panic during reading.\n    // * Use `File::take` to obtain a reader which yields no more than `size` bytes.","sourceCodeStart":191,"sourceCodeEnd":227,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/utils/mod.rs#L191-L227","documentation":"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.","triggerScenarios":"Thrown at crates/oxc_linter/src/utils/mod.rs:209 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Reject or skip the oversized file with a clear user-facing error","Read the file in chunks or memory-map it instead of one arena allocation"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}