{"record":{"id":"7fdecd253f4dfd21","repo":"windmill-labs/windmill","slug":"fdopen-is-not-supported-7fdecd","errorCode":null,"errorMessage":"fdopen is not supported","messagePattern":"fdopen is not supported","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/parsers/windmill-parser-r/src/wasm_libc.rs","lineNumber":251,"sourceCode":"\n#[no_mangle]\npub unsafe extern \"C\" fn fprintf(_file: *mut c_void, _format: *const c_void, _args: ...) -> c_int {\n    panic!(\"fprintf is not supported\");\n}\n\n#[no_mangle]\npub unsafe extern \"C\" fn fputs(_s: *const c_void, _file: *mut c_void) -> c_int {\n    panic!(\"fputs is not supported\");\n}\n\n#[no_mangle]\npub unsafe extern \"C\" fn fputc(_c: c_int, _file: *mut c_void) -> c_int {\n    panic!(\"fputc is not supported\");\n}\n\n#[no_mangle]\npub unsafe extern \"C\" fn fdopen(_fd: c_int, _mode: *const c_void) -> *mut c_void {\n    panic!(\"fdopen is not supported\");\n}\n\n#[no_mangle]\npub unsafe extern \"C\" fn fclose(_file: *mut c_void) -> c_int {\n    panic!(\"fclose is not supported\");\n}\n\n#[no_mangle]\npub unsafe extern \"C\" fn fwrite(\n    _ptr: *const c_void,\n    _size: usize,\n    _nmemb: usize,\n    _stream: *mut c_void,\n) -> usize {\n    panic!(\"fwrite is not supported\");\n}\n\n#[no_mangle]","sourceCodeStart":233,"sourceCodeEnd":269,"githubUrl":"https://github.com/windmill-labs/windmill/blob/e474e8803ce2ff5c2df09a58dab51d45f5c922ca/backend/parsers/windmill-parser-r/src/wasm_libc.rs#L233-L269","documentation":"`fdopen` (associate a stream with an existing file descriptor) is an unimplemented libc stub in the R parser WASM runtime that panics on entry. The sandbox deliberately exposes no file-descriptor/FILE* machinery, so any attempt to open a stream around a fd aborts.","triggerScenarios":"Calling the exported `fdopen` shim at backend/parsers/windmill-parser-r/src/wasm_libc.rs:251, e.g. compiled C or R runtime code tries to wrap a raw fd in a FILE* stream.","commonSituations":"Ported C library code opens streams from descriptors; R code reads/writes files through low-level paths; a dependency expects POSIX file semantics unavailable under WASM.","solutions":["Refactor the code to use the parser's supported I/O API instead of fd-based streams","Implement fdopen in wasm_libc.rs if descriptor-backed streams are actually needed (rare; requires full FILE* emulation)","Remove the dependency that requires POSIX file streams","Pre-process R inputs to avoid file-based code paths before parsing/execution"],"exampleFix":"// before (stub)\n#[no_mangle]\npub unsafe extern \"C\" fn fdopen(_fd: c_int, _mode: *const c_void) -> *mut c_void {\n    panic!(\"fdopen is not supported\");\n}\n// after (explicit failure instead of panic, if a caller must probe)\n#[no_mangle]\npub unsafe extern \"C\" fn fdopen(_fd: c_int, _mode: *const c_void) -> *mut c_void {\n    std::ptr::null_mut() // callers check for NULL and fall back\n}","handlingStrategy":"try-catch","validationCode":"// Pre-check: the sandbox has no file-descriptor support; reject fd/stream-based code paths\nif (/\\b(fdopen|fileno|open|creat)\\s*\\(/.test(cOrRSource)) {\n  throw new Error(\"fd-based streams (fdopen) are unsupported in the R parser WASM sandbox\");\n}","typeGuard":"fn fdopen_supported(fd_provided: bool) -> bool { !fd_provided } // no fd-backed streams exist; any fd path is unsupported","tryCatchPattern":"match std::panic::catch_unwind(|| run_wasm_r(source)) {\n    Err(p) if panic_msg(&p).contains(\"fdopen is not supported\") => {\n        Err(Error::UnsupportedFileIo(\"rewrite the code to avoid fdopen; use supported I/O\"))\n    }\n    other => other.map_err(Error::from),\n}","preventionTips":["Never pass file descriptors or expect POSIX stream semantics inside the WASM parser","Use the host's file APIs outside the sandbox instead of in-sandbox fdopen","Document fdopen/fclose/fopen as absent symbols for anyone porting C into the parser","Fail fast with a clear message rather than letting the panic surface raw"],"tags":["wasm","libc","rust","file-io"],"backgroundTag":"wasm-libc-function-not-supported","analyzedSha":"e474e8803ce2ff5c2df09a58dab51d45f5c922ca","analyzedAt":"2026-09-03T12:38:19.024Z","contentChangedAt":"2026-09-03T12:38:19.024Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}