{"record":{"id":"67b4d13dea950b8a","repo":"ipfs/kubo","slug":"cannot-specify-negative-count","errorCode":null,"errorMessage":"cannot specify negative 'count'","messagePattern":"cannot specify negative 'count'","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/commands/files.go","lineNumber":884,"sourceCode":"\t\tfilen, err := rfd.Size()\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\n\t\tif int64(offset) > filen {\n\t\t\treturn fmt.Errorf(\"offset was past end of file (%d > %d)\", offset, filen)\n\t\t}\n\n\t\t_, err = rfd.Seek(int64(offset), io.SeekStart)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\n\t\tvar r io.Reader = &contextReaderWrapper{R: rfd, ctx: req.Context}\n\t\tcount, found := req.Options[filesCountOptionName].(int64)\n\t\tif found {\n\t\t\tif count < 0 {\n\t\t\t\treturn fmt.Errorf(\"cannot specify negative 'count'\")\n\t\t\t}\n\t\t\tr = io.LimitReader(r, int64(count))\n\t\t}\n\t\treturn res.Emit(r)\n\t},\n}\n\ntype contextReader interface {\n\tCtxReadFull(context.Context, []byte) (int, error)\n}\n\ntype contextReaderWrapper struct {\n\tR   contextReader\n\tctx context.Context\n}\n\nfunc (crw *contextReaderWrapper) Read(b []byte) (int, error) {\n\treturn crw.R.CtxReadFull(crw.ctx, b)","sourceCodeStart":866,"sourceCodeEnd":902,"githubUrl":"https://github.com/ipfs/kubo/blob/329838acdfafae224582930457efe80aa217afc0/core/commands/files.go#L866-L902","documentation":"Guard in the `ipfs files write` handler: before wrapping the input reader with io.LimitReader, it rejects a --count option that was parsed as a negative int64. It fires on input validation, not on file I/O — the write has not started yet.","triggerScenarios":"Thrown at core/commands/files.go:884 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Pass a non-negative --count to `ipfs files write`, or omit the option to write the entire stream.","Fix the calling script that computes count so it cannot produce a negative value (e.g. clamp with max(0, n))."],"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"}