{"record":{"id":"de7f5b092bc7d142","repo":"BigPizzaV3/CodexPlusPlus","slug":"unexpected-file-type-or-size","errorCode":null,"errorMessage":"Unexpected file type or size","messagePattern":"Unexpected file type or size","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/codex-plus-core/src/native_browser.rs","lineNumber":185,"sourceCode":"    let _guards = pin_parents(path)?;\n    let mut options = OpenOptions::new();\n    options.read(true);\n    #[cfg(windows)]\n    {\n        use std::os::windows::fs::OpenOptionsExt;\n        options.share_mode(0x1).custom_flags(0x00200000);\n    }\n    let file = options.open(path)?;\n    let meta = file.metadata()?;\n    #[cfg(windows)]\n    {\n        use std::os::windows::fs::MetadataExt;\n        ensure!(\n            meta.file_attributes() & 0x400 == 0,\n            \"File is a reparse point\"\n        );\n    }\n    ensure!(\n        meta.is_file() && meta.len() <= limit,\n        \"Unexpected file type or size\"\n    );\n    let mut bytes = Vec::new();\n    file.take(limit + 1).read_to_end(&mut bytes)?;\n    ensure!(\n        bytes.len() as u64 <= limit,\n        \"File grew beyond the size limit\"\n    );\n    Ok(bytes)\n}\n\nfn write_new(path: &Path, bytes: &[u8]) -> Result<File> {\n    let _guards = pin_parents(path)?;\n    let mut file = OpenOptions::new().write(true).create_new(true).open(path)?;\n    file.write_all(bytes)?;\n    file.sync_all()?;\n    Ok(file)","sourceCodeStart":167,"sourceCodeEnd":203,"githubUrl":"https://github.com/BigPizzaV3/CodexPlusPlus/blob/b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6/crates/codex-plus-core/src/native_browser.rs#L167-L203","documentation":"After reparse-point rejection, read_regular verifies the opened path is actually a regular file (meta.is_file()) and its metadata size is within the caller-supplied limit (e.g. MAX_SERVICE = 32 MiB for browser-service.mjs). It throws when the target is a special/non-regular file or is larger than the allowed size. This prevents reading devices, directories, or absurdly large files into memory during integrity patching.","triggerScenarios":"Reading a runtime file that is a directory, device, or other non-regular entry; or reading a file whose on-disk size exceeds the per-call limit (32 MiB for the browser service script) — e.g. a service script bloated by appended content or a wrong path passed that resolves to an oversized artifact.","commonSituations":"A corrupted or tampered installation where browser-service.mjs grew beyond 32 MiB (e.g. the adapter applied repeatedly, appending content each run); pointing the tool at the wrong file; unusual filesystem objects (named-pipe-like entries) placed at the expected path.","solutions":["Verify the path resolves to the intended regular file (`dir <path>` / `Get-Item <path>`) and fix a wrong-path configuration if so.","Check the file size (`Get-Item <path>.Length`); if it exceeds 32 MiB, restore the original browser-service.mjs from a clean Codex installation.","If a previous patch was applied multiple times and grew the file, undo via the library's restore path (restore_all) or reinstall the runtime to reset the file.","Retry read once the target is a normal, correctly-sized file."],"exampleFix":"// before: browser-service.mjs is 41 MB (repeatedly patched)\n// after: restore the pristine file from a clean install, then re-run prepare\nCopy-Item \"C:\\clean-install\\...\\browser-service.mjs\" \"$env:LOCALAPPDATA\\OpenAI\\Codex\\runtimes\\cua_node\\bin\\node_modules\\@oai\\browser-desktop\\scripts\\browser-service.mjs\"","handlingStrategy":"validation","validationCode":"const MAX_SERVICE: u64 = 32 * 1024 * 1024;\nfn assert_readable_size(path: &Path) -> std::io::Result<()> {\n    let meta = std::fs::metadata(path)?;\n    if !meta.is_file() {\n        return Err(std::io::Error::new(\n            std::io::ErrorKind::InvalidInput,\n            format!(\"{} is not a regular file\", path.display()),\n        ));\n    }\n    if meta.len() > MAX_SERVICE {\n        return Err(std::io::Error::new(\n            std::io::ErrorKind::InvalidData,\n            format!(\"{} is {} bytes, limit is {}\", path.display(), meta.len(), MAX_SERVICE),\n        ));\n    }\n    Ok(())\n}","typeGuard":"fn fits_limit(meta: &std::fs::Metadata, limit: u64) -> bool {\n    meta.is_file() && meta.len() <= limit\n}","tryCatchPattern":"match result {\n    Err(e) if e.to_string().contains(\"Unexpected file type or size\") => {\n        eprintln!(\"Target is not a regular file or exceeds the size limit; restore the pristine runtime file: {e}\");\n    }\n    Err(e) => return Err(e.into()),\n    Ok(bytes) => process(bytes),\n}","preventionTips":["Never patch the browser service file more than once; restore before re-running prepare","Monitor the service file size after updates; a healthy build is well under 32 MiB","Keep a backup of the pristine browser-service.mjs from a clean installation","Verify file sizes with Get-Item before automation runs"],"tags":["filesystem","file-size","validation","integrity"],"backgroundTag":"file-size-limit-exceeded","analyzedSha":"b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6","analyzedAt":"2026-09-19T23:35:21.129Z","contentChangedAt":"2026-09-19T23:35:21.129Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}