{"record":{"id":"cfd55a51ce20a0d3","repo":"JuliusBrussee/caveman","slug":"cachebench-invalid-trace-read-limits","errorCode":null,"errorMessage":"cachebench: invalid trace read limits","messagePattern":"cachebench: invalid trace read limits","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cacheengine/cachebench/trace.go","lineNumber":281,"sourceCode":"\tMaxLineBytes int\n\tMaxRecords   int\n\tMaxBodyBytes int\n}\n\n// DefaultTraceReadLimits supports public-corpus traces while bounding retained memory.\nfunc DefaultTraceReadLimits() TraceReadLimits {\n\treturn TraceReadLimits{MaxLineBytes: 96 << 20, MaxRecords: 100_000, MaxBodyBytes: 64 << 20}\n}\n\n// ReadTraceJSONL reads trace records using conservative default resource limits.\nfunc ReadTraceJSONL(reader io.Reader) ([]TraceRecord, error) {\n\treturn ReadTraceJSONLWithLimits(reader, DefaultTraceReadLimits())\n}\n\n// ReadTraceJSONLWithLimits reads strict trace JSONL under explicit resource limits.\nfunc ReadTraceJSONLWithLimits(reader io.Reader, limits TraceReadLimits) ([]TraceRecord, error) {\n\tif limits.MaxLineBytes <= 0 || limits.MaxLineBytes > 512<<20 || limits.MaxRecords <= 0 || limits.MaxRecords > 1_000_000 || limits.MaxBodyBytes <= 0 || limits.MaxBodyBytes > 256<<20 {\n\t\treturn nil, errors.New(\"cachebench: invalid trace read limits\")\n\t}\n\tscanner := bufio.NewScanner(reader)\n\tinitial := 64 * 1024\n\tif limits.MaxLineBytes < initial {\n\t\tinitial = limits.MaxLineBytes\n\t}\n\tscanner.Buffer(make([]byte, initial), limits.MaxLineBytes)\n\tseen := map[string]bool{}\n\tvar records []TraceRecord\n\tfor line := 1; scanner.Scan(); line++ {\n\t\traw := bytes.TrimSpace(scanner.Bytes())\n\t\tif len(raw) == 0 {\n\t\t\tcontinue\n\t\t}\n\t\tif len(records) >= limits.MaxRecords {\n\t\t\treturn nil, fmt.Errorf(\"cachebench: trace exceeds record limit %d\", limits.MaxRecords)\n\t\t}\n\t\tif !validUniqueJSONObject(raw) {","sourceCodeStart":263,"sourceCodeEnd":299,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/766dce6b1394ebb56a3090748d5a0240a5aefb36/cacheengine/cachebench/trace.go#L263-L299","documentation":"ReadTraceJSONLWithLimits was called with a TraceReadLimits containing a non-positive MaxLineBytes, MaxRecords, or MaxBodyBytes. The reader refuses unlimited/zero limits because they exist to bound retained memory for public-corpus traces.","triggerScenarios":"Thrown at cacheengine/cachebench/trace.go:281 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Pass limits with all three fields positive, e.g. DefaultTraceReadLimits()","Raise specific limit values rather than zeroing them to disable a bound"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"766dce6b1394ebb56a3090748d5a0240a5aefb36","analyzedAt":"2026-08-18T03:14:35.516Z","contentChangedAt":"2026-08-18T03:14:35.516Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}