{"record":{"id":"88cff1f440ee6ba4","repo":"wavetermdev/waveterm","slug":"file-data-size-d-exceeds-transfer-limit-of-d-byt","errorCode":null,"errorMessage":"file data size %d exceeds transfer limit of %d bytes","messagePattern":"file data size (.+?) exceeds transfer limit of (.+?) bytes","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/remote/fileshare/wshfs/wshfs.go","lineNumber":171,"sourceCode":"\tif err != nil {\n\t\treturn nil, err\n\t}\n\treturn stat(conn)\n}\n\nfunc stat(conn *connparse.Connection) (*wshrpc.FileInfo, error) {\n\treturn wshclient.RemoteFileInfoCommand(RpcClient, conn.Path, &wshrpc.RpcOpts{Route: wshutil.MakeConnectionRouteId(conn.Host)})\n}\n\nfunc PutFile(ctx context.Context, data wshrpc.FileData) error {\n\tlog.Printf(\"PutFile: %v\", data.Info.Path)\n\tconn, err := parseConnection(ctx, data.Info.Path)\n\tif err != nil {\n\t\treturn err\n\t}\n\tdataSize := base64.StdEncoding.DecodedLen(len(data.Data64))\n\tif dataSize > RemoteFileTransferSizeLimit {\n\t\treturn fmt.Errorf(\"file data size %d exceeds transfer limit of %d bytes\", dataSize, RemoteFileTransferSizeLimit)\n\t}\n\tinfo := data.Info\n\tif info == nil {\n\t\tinfo = &wshrpc.FileInfo{Opts: &wshrpc.FileOpts{}}\n\t} else if info.Opts == nil {\n\t\tinfo.Opts = &wshrpc.FileOpts{}\n\t}\n\tinfo.Path = conn.Path\n\tinfo.Opts.Truncate = true\n\tdata.Info = info\n\treturn wshclient.RemoteWriteFileCommand(RpcClient, data, &wshrpc.RpcOpts{Route: wshutil.MakeConnectionRouteId(conn.Host)})\n}\n\nfunc Append(ctx context.Context, data wshrpc.FileData) error {\n\tlog.Printf(\"Append: %v\", data.Info.Path)\n\tconn, err := parseConnection(ctx, data.Info.Path)\n\tif err != nil {\n\t\treturn err","sourceCodeStart":153,"sourceCodeEnd":189,"githubUrl":"https://github.com/wavetermdev/waveterm/blob/a4447c1563b2df285ab89e76c82f91e1a1a49c1e/pkg/remote/fileshare/wshfs/wshfs.go#L153-L189","documentation":"PutFile enforces RemoteFileTransferSizeLimit (32 MiB) on the decoded size of data.Data64, computed via base64.StdEncoding.DecodedLen. Writes whose payload exceeds this limit are rejected locally with this error instead of being sent to the remote, protecting against unbounded RPC payloads.","triggerScenarios":"Calling wshfs.PutFile (via FileCreateCommand/FileWriteCommand) with Data64 whose base64 payload decodes to more than 32*1024*1024 bytes — e.g. base64.DecodedLen(len(Data64)) > 33554432.","commonSituations":"Writing a large binary, video, database dump, or log file in a single PutFile call; uploading a file that grew past the limit since the code was written; copying files without chunking.","solutions":["Split the write: write the first chunk with PutFile then add remaining data with wshfs.Append in <=32 MiB chunks","Compress data before base64-encoding if it compresses well","Use the streaming APIs (FileStream/stream write) instead of a single PutFile for large files","Check file size with Stat before writing to decide on a chunked strategy"],"exampleFix":"// before\nif len(content) > 40*1024*1024 {\n    wshfs.PutFile(ctx, wshrpc.FileData{Info: info, Data64: b64(content)}) // errors\n}\n// after\nconst chunk = 8 * 1024 * 1024\nfirst := true\nfor off := 0; off < len(content); off += chunk {\n    end := min(off+chunk, len(content))\n    b64data := base64.StdEncoding.EncodeToString(content[off:end])\n    if first {\n        err = wshfs.PutFile(ctx, wshrpc.FileData{Info: info, Data64: b64data}); first = false\n    } else {\n        err = wshfs.Append(ctx, wshrpc.FileData{Info: info, Data64: b64data})\n    }\n}","handlingStrategy":"validation","validationCode":"const transferLimit = 32 * 1024 * 1024\nif base64.StdEncoding.DecodedLen(len(data.Data64)) > transferLimit {\n    return fmt.Errorf(\"payload exceeds wshfs 32 MiB PutFile limit\")\n}","typeGuard":null,"tryCatchPattern":"err := wshfs.PutFile(ctx, data)\nif err != nil {\n    if strings.Contains(err.Error(), \"exceeds transfer limit\") {\n        return chunkedWrite(ctx, data) // PutFile first chunk + Append rest\n    }\n    return err\n}","preventionTips":["Check decoded size (DecodedLen of base64) against RemoteFileTransferSizeLimit before writing","Use a chunked write helper (PutFile + Append) for arbitrarily sized content","Stat large sources first and choose streaming vs single-shot accordingly","Keep a shared chunk-size constant safely below 32 MiB"],"tags":["go","file-transfer","limit"],"backgroundTag":"payload-size-limit-exceeded","analyzedSha":"a4447c1563b2df285ab89e76c82f91e1a1a49c1e","analyzedAt":"2026-09-01T15:26:23.972Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}