{"record":{"id":"8a779b396a2c15ba","repo":"golang/go","slug":"negative-size","errorCode":null,"errorMessage":"negative size","messagePattern":"negative size","errorType":"exception","errorClass":"entryNotFoundError","httpStatus":null,"severity":"error","filePath":"src/cmd/go/internal/cache/cache.go","lineNumber":245,"sourceCode":"\tetime, entry := entry[1:1+20], entry[1+20:]\n\tvar buf [HashSize]byte\n\tif _, err := hex.Decode(buf[:], eid); err != nil {\n\t\treturn missing(fmt.Errorf(\"decoding ID: %v\", err))\n\t} else if buf != id {\n\t\treturn missing(errors.New(\"mismatched ID\"))\n\t}\n\tif _, err := hex.Decode(buf[:], eout); err != nil {\n\t\treturn missing(fmt.Errorf(\"decoding output ID: %v\", err))\n\t}\n\ti := 0\n\tfor i < len(esize) && esize[i] == ' ' {\n\t\ti++\n\t}\n\tsize, err := strconv.ParseInt(string(esize[i:]), 10, 64)\n\tif err != nil {\n\t\treturn missing(fmt.Errorf(\"parsing size: %v\", err))\n\t} else if size < 0 {\n\t\treturn missing(errors.New(\"negative size\"))\n\t}\n\ti = 0\n\tfor i < len(etime) && etime[i] == ' ' {\n\t\ti++\n\t}\n\ttm, err := strconv.ParseInt(string(etime[i:]), 10, 64)\n\tif err != nil {\n\t\treturn missing(fmt.Errorf(\"parsing timestamp: %v\", err))\n\t} else if tm < 0 {\n\t\treturn missing(errors.New(\"negative timestamp\"))\n\t}\n\n\tc.markUsed(c.fileName(id, \"a\"))\n\n\treturn Entry{buf, size, time.Unix(0, tm)}, nil\n}\n\n// GetFile looks up the action ID in the cache and returns","sourceCodeStart":227,"sourceCodeEnd":263,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/go/internal/cache/cache.go#L227-L263","documentation":"The size field in the cache entry header was successfully parsed as a decimal integer but the value is negative. The entry format space-pads the size to 20 bytes, and the parser strips leading spaces then calls strconv.ParseInt. A valid cache entry must have a non-negative output size, so a negative value means the size field bytes are corrupted.","triggerScenarios":"DiskCache.get(id) parses the 20-byte space-padded size field (esize) with strconv.ParseInt(s, 10, 64) after stripping leading spaces. The parse succeeds but size < 0.","commonSituations":"Byte-level corruption specifically in the size field region of the entry file; a different Go version with a different entry format writing to the same cache; storage errors affecting the specific disk sectors holding these bytes.","solutions":["Run go clean -cache to purge corrupt entries","Verify all builds sharing the cache use the same Go version","Run disk diagnostics (SMART, fsck) if corruption recurs","Move GOCACHE to more reliable storage"],"exampleFix":"// before: corrupt size field in cache entry\n// $ go build ./... # fails with 'cache entry not found: negative size'\n\n// after: clean cache\n// $ go clean -cache && go build ./...","handlingStrategy":"try-catch","validationCode":"// No pre-check can predict field-level corruption.\n// Ensure hardware reliability and cache hygiene instead.\n// Consider GOCACHE=\"\" to disable caching for debugging.","typeGuard":"func isNegativeSize(err error) bool {\n    return err != nil && strings.Contains(err.Error(), \"negative size\")\n}","tryCatchPattern":"// entry, err := cache.Get(id)\n// if err != nil {\n//     // Negative size — corrupt size field. Rebuild output.\n//     output = rebuild()\n// }","preventionTips":["Run go clean -cache after Go version upgrades","Run memtest and disk SMART diagnostics periodically","Keep the cache on reliable local storage","Monitor for recurring corruption which signals hardware issues"],"tags":["go","build-cache","corruption","disk-cache"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T08:17:17.861Z"}