{"record":{"id":"88657cc58b9a664b","repo":"windmill-labs/windmill","slug":"fwrite-is-not-supported-88657c","errorCode":null,"errorMessage":"fwrite is not supported","messagePattern":"fwrite is not supported","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/parsers/windmill-parser-r/src/wasm_libc.rs","lineNumber":266,"sourceCode":"\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]\npub unsafe extern \"C\" fn vsnprintf(\n    _buf: *mut c_char,\n    _size: usize,\n    _format: *const c_char,\n    _args: ...\n) -> c_int {\n    panic!(\"vsnprintf is not supported\");\n}\n\n#[no_mangle]\npub extern \"C\" fn clock_gettime(ptr: usize, new_size: usize) {\n    panic!(\"clock_gettime is not supported\");\n}\n\n// int snprintf( char* restrict buffer, size_t bufsz, const char* restrict format, ... );","sourceCodeStart":248,"sourceCodeEnd":284,"githubUrl":"https://github.com/windmill-labs/windmill/blob/e474e8803ce2ff5c2df09a58dab51d45f5c922ca/backend/parsers/windmill-parser-r/src/wasm_libc.rs#L248-L284","documentation":"`fwrite` (write blocks of memory to a FILE*) is an unimplemented libc shim in the R parser WASM runtime that panics on entry. The sandbox provides no stream output, so any binary/structured write to a FILE* aborts the WASM execution.","triggerScenarios":"Calling the exported `fwrite` shim at backend/parsers/windmill-parser-r/src/wasm_libc.rs:266, reached when compiled code serializes data or writes buffers to stdout/stderr/files via fwrite.","commonSituations":"R code calls writeBin/saveRDS-style paths compiled to fwrite; C dependencies dump binary buffers; logging libraries write records with fwrite.","solutions":["Rewrite the producing code to return data through supported channels instead of stream writes","Implement fwrite in wasm_libc.rs to forward the buffer to the host output","Remove or replace the dependency that performs binary stream writes","Convert output to string-based calls (if printf-family variants are supported) before writing"],"exampleFix":"// before (stub)\n#[no_mangle]\npub unsafe extern \"C\" fn fwrite(_ptr: *const c_void, _size: usize, _nmemb: usize, _stream: *mut c_void) -> usize {\n    panic!(\"fwrite is not supported\");\n}\n// after (forward buffer to host stdout)\n#[no_mangle]\npub unsafe extern \"C\" fn fwrite(ptr: *const c_void, size: usize, nmemb: usize, _stream: *mut c_void) -> usize {\n    let bytes = std::slice::from_raw_parts(ptr as *const u8, size.saturating_mul(nmemb));\n    use std::io::Write;\n    let n = std::io::stdout().write(bytes).unwrap_or(0);\n    n as usize\n}","handlingStrategy":"try-catch","validationCode":"// Reject binary stream writes before running in the sandbox\nif (/\\b(fwrite|writeBin|saveRDS)\\s*\\(/.test(rSource)) {\n  throw new Error(\"binary stream writes (fwrite) are unsupported in the R parser WASM\");\n}","typeGuard":"fn fwrite_target_is_host(stream: *mut c_void) -> bool { false } // no valid FILE* exists; all fwrite targets would panic","tryCatchPattern":"match std::panic::catch_unwind(|| run_wasm_r(source)) {\n    Ok(v) => v,\n    Err(p) if panic_msg(&p).contains(\"fwrite is not supported\") => {\n        // re-serialize output via a supported channel (return value / string output) and retry\n        run_wasm_r(&rewrite_stream_writes_to_return_value(source))\n    }\n    Err(p) => std::panic::resume_unwind(p),\n}","preventionTips":["Return data as values instead of writing buffers to streams in sandboxed R code","Convert binary outputs to supported encodings (base64 string, structured return)","Scan compiled dependencies for fwrite/writeBin-style output before deployment","Centralize WASM panic handling so every 'not supported' stub maps to a documented error"],"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"}