{"record":{"id":"cf3882357520e5d9","repo":"golang/go","slug":"bad-checksum","errorCode":null,"errorMessage":"bad checksum","messagePattern":"bad checksum","errorType":"exception","errorClass":"entryNotFoundError","httpStatus":null,"severity":"error","filePath":"src/cmd/go/internal/cache/cache.go","lineNumber":291,"sourceCode":"\t\treturn \"\", Entry{}, &entryNotFoundError{Err: err}\n\t}\n\tif info.Size() != entry.Size {\n\t\treturn \"\", Entry{}, &entryNotFoundError{Err: errors.New(\"file incomplete\")}\n\t}\n\treturn file, entry, nil\n}\n\n// GetBytes looks up the action ID in the cache and returns\n// the corresponding output bytes.\n// GetBytes should only be used for data that can be expected to fit in memory.\nfunc GetBytes(c Cache, id ActionID) ([]byte, Entry, error) {\n\tentry, err := c.Get(id)\n\tif err != nil {\n\t\treturn nil, entry, err\n\t}\n\tdata, _ := os.ReadFile(c.OutputFile(entry.OutputID))\n\tif sha256.Sum256(data) != entry.OutputID {\n\t\treturn nil, entry, &entryNotFoundError{Err: errors.New(\"bad checksum\")}\n\t}\n\treturn data, entry, nil\n}\n\n// GetMmap looks up the action ID in the cache and returns\n// the corresponding output bytes.\n// GetMmap should only be used for data that can be expected to fit in memory.\n// The boolean result indicates whether the file was opened.\n// If it is true, the caller should avoid attempting\n// to write to the file on Windows, because Windows locks\n// the open file, and writes to it will fail.\nfunc GetMmap(c Cache, id ActionID) ([]byte, Entry, bool, error) {\n\tentry, err := c.Get(id)\n\tif err != nil {\n\t\treturn nil, entry, false, err\n\t}\n\tmd, opened, err := mmap.Mmap(c.OutputFile(entry.OutputID))\n\tif err != nil {","sourceCodeStart":273,"sourceCodeEnd":309,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/go/internal/cache/cache.go#L273-L309","documentation":"In GetBytes(), the SHA-256 hash of the output data read from disk does not match the OutputID stored in the cache entry. This is a content-integrity checksum that catches silent data corruption in the output file — the file exists and has the right size but its bytes have changed. The OutputID IS the SHA-256 hash of the output, so any mismatch means corruption.","triggerScenarios":"GetBytes(c, id) reads the output file bytes via os.ReadFile, computes sha256.Sum256(data), and compares against entry.OutputID. The comparison fails — the hashes differ.","commonSituations":"Silent disk corruption (bit rot on aging storage); failing storage hardware (bad sectors, controller errors); cosmic ray bit-flips on unreliable hardware; external modification of cached output files; RAM errors corrupting data during read.","solutions":["Run go clean -cache to purge corrupted output files","Run disk SMART diagnostics (smartctl) and memory tests (memtest86)","Move cache to more reliable storage (SSD vs aging HDD, RAID)","If corruption recurs frequently, investigate hardware health comprehensively"],"exampleFix":"// before: checksum mismatch in cached output\n// $ go build ./... # fails with 'cache entry not found: bad checksum'\n\n// after: clean cache and check hardware\n// $ go clean -cache && go build ./...\n// $ smartctl -H /dev/sda  # if issue recurs, check disk health","handlingStrategy":"try-catch","validationCode":"// Verify output integrity by computing SHA-256 before trusting cached data.\nimport \"crypto/sha256\"\n\nfunc verifyOutputChecksum(path string, expected cache.OutputID) error {\n    data, err := os.ReadFile(path)\n    if err != nil {\n        return err\n    }\n    actual := sha256.Sum256(data)\n    if actual != expected {\n        return fmt.Errorf(\"checksum mismatch for %s\", path)\n    }\n    return nil\n}","typeGuard":"func isBadChecksum(err error) bool {\n    return err != nil && strings.Contains(err.Error(), \"bad checksum\")\n}","tryCatchPattern":"// data, entry, err := cache.GetBytes(c, id)\n// if err != nil {\n//     // Bad checksum — output data silently corrupted.\n//     // Rebuild the output from source.\n//     data = rebuild()\n// }\n//\n// // GetBytes already verifies the checksum internally,\n// // so if it returns nil error, the data is verified.","preventionTips":["Run go clean -cache periodically to purge silently corrupted entries","Monitor disk health with SMART diagnostics — bit rot indicates failing storage","Run memtest periodically to catch RAM errors that corrupt data during read/write","Store cache on SSDs rather than aging HDDs for better data integrity","If checksum failures recur, suspect hardware — run comprehensive diagnostics"],"tags":["go","build-cache","corruption","disk-cache","checksum","integrity"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T06:17:24.410Z"}