{"record":{"id":"81484ca4e381e2b7","repo":"ipfs/kubo","slug":"cannot-have-negative-byte-count","errorCode":null,"errorMessage":"cannot have negative byte count","messagePattern":"cannot have negative byte count","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/commands/files.go","lineNumber":1152,"sourceCode":"\t\t\t\tif _, err := mfs.FlushPath(req.Context, nd.FilesRoot, parent); err != nil {\n\t\t\t\t\tif retErr == nil {\n\t\t\t\t\t\tretErr = err\n\t\t\t\t\t} else {\n\t\t\t\t\t\tflog.Error(\"files: flushing the parent folder\", err)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}()\n\n\t\tif trunc {\n\t\t\tif err := wfd.Truncate(0); err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\t}\n\n\t\tcount, countfound := req.Options[filesCountOptionName].(int64)\n\t\tif countfound && count < 0 {\n\t\t\treturn fmt.Errorf(\"cannot have negative byte count\")\n\t\t}\n\n\t\t_, err = wfd.Seek(int64(offset), io.SeekStart)\n\t\tif err != nil {\n\t\t\tflog.Error(\"seekfail: \", err)\n\t\t\treturn err\n\t\t}\n\n\t\tvar r io.Reader\n\t\tr, err = cmdenv.GetFileArg(req.Files.Entries())\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\tif countfound {\n\t\t\tr = io.LimitReader(r, int64(count))\n\t\t}\n\n\t\t_, err = io.Copy(wfd, r)","sourceCodeStart":1134,"sourceCodeEnd":1170,"githubUrl":"https://github.com/ipfs/kubo/blob/329838acdfafae224582930457efe80aa217afc0/core/commands/files.go#L1134-L1170","documentation":"Guard in the `ipfs files write` handler after truncation handling: a --count option parsed to a negative int64 is rejected before seeking and writing. Validation of the byte-count option, not an I/O failure.","triggerScenarios":"Thrown at core/commands/files.go:1152 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Pass a non-negative --count, or omit it to write until the input ends.","Fix the script or wrapper that derives the count value so it cannot be negative."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"329838acdfafae224582930457efe80aa217afc0","analyzedAt":"2026-09-03T18:30:52.135Z","contentChangedAt":"2026-09-03T18:30:52.135Z","schemaVersion":2},"datasetVersion":"2026-09-11T00:17:11.886Z"}