{"record":{"id":"3a169400878ea019","repo":"wavetermdev/waveterm","slug":"input-exceeds-maximum-file-size-of-d-bytes","errorCode":null,"errorMessage":"input exceeds maximum file size of %d bytes","messagePattern":"input exceeds maximum file size of (.+?) bytes","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/wsh/cmd/wshcmd-file-util.go","lineNumber":76,"sourceCode":"\t}\n\n\tconst chunkSize = wshrpc.FileChunkSize // 32KB chunks\n\tbuf := make([]byte, chunkSize)\n\ttotalWritten := int64(0)\n\n\tfor {\n\t\tn, err := reader.Read(buf)\n\t\tif err == io.EOF {\n\t\t\tbreak\n\t\t}\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"reading input: %w\", err)\n\t\t}\n\n\t\t// Check total size\n\t\ttotalWritten += int64(n)\n\t\tif totalWritten > MaxFileSize {\n\t\t\treturn fmt.Errorf(\"input exceeds maximum file size of %d bytes\", MaxFileSize)\n\t\t}\n\n\t\t// Prepare and send chunk\n\t\tchunk := buf[:n]\n\t\tappendData := fileData\n\t\tappendData.Data64 = base64.StdEncoding.EncodeToString(chunk)\n\n\t\terr = wshclient.FileAppendCommand(RpcClient, appendData, &wshrpc.RpcOpts{Timeout: int64(fileTimeout)})\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"appending chunk to file: %w\", err)\n\t\t}\n\t}\n\n\treturn nil\n}\n\nfunc streamReadFromFile(ctx context.Context, fileData wshrpc.FileData, writer io.Writer) error {\n\tbroker := RpcClient.StreamBroker","sourceCodeStart":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/wavetermdev/waveterm/blob/a4447c1563b2df285ab89e76c82f91e1a1a49c1e/cmd/wsh/cmd/wshcmd-file-util.go#L58-L94","documentation":"streamWriteToFile enforces MaxFileSize as a hard cap on streamed input. When the cumulative bytes read exceed the limit, it aborts with \"input exceeds maximum file size of %d bytes\" rather than shipping an oversized file over RPC.","triggerScenarios":"Piping or copying input larger than MaxFileSize into `wsh` file streaming (e.g. `cat bigfile | wsh cp - remote:file`), where totalWritten > MaxFileSize after a chunk read.","commonSituations":"Redirecting huge log dumps, VM images, or datasets into wsh without checking size; underestimating binary sizes; accidentally piping an unbounded stream like `yes` or live logs.","solutions":["Check MaxFileSize (in the wsh cmd package) and verify your input's size with `ls -l` or `du` before streaming.","Split or compress the input so it fits under the limit, then transfer in parts.","Use scp/rsync/ssh directly for files larger than the cap.","If the limit is too small for your workflow, rebuild wsh with an adjusted MaxFileSize constant (at your own risk)."],"exampleFix":"// before\ncat 200GB.dump | wsh cp - remote:dump.bin\n// after\nsplit -b 90M 200GB.dump part_ && for f in part_*; do wsh cp \"$f\" \"remote:dump_$f\"; done","handlingStrategy":"validation","validationCode":"fi, err := os.Stat(inputPath)\nif err == nil && fi.Size() > MaxFileSize {\n    return fmt.Errorf(\"input %s is %d bytes, exceeds limit %d\", inputPath, fi.Size(), MaxFileSize)\n}","typeGuard":null,"tryCatchPattern":"if err := streamWriteToFile(fileData, reader); err != nil {\n    if strings.Contains(err.Error(), \"maximum file size\") {\n        // split/compress the input or use rsync/scp instead\n    }\n}","preventionTips":["Check input size against MaxFileSize before streaming","Split or compress oversized inputs","Use scp/rsync for transfers beyond the cap","Don't pipe unbounded streams (logs, yes) into wsh"],"tags":["streaming","limit","validation"],"backgroundTag":"file-size-limit-exceeded","analyzedSha":"a4447c1563b2df285ab89e76c82f91e1a1a49c1e","analyzedAt":"2026-09-01T15:26:23.972Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}