{"record":{"id":"7501c5c2d3adf5d2","repo":"avajs/ava","slug":"checksum-mismatch","errorCode":null,"errorMessage":"Checksum mismatch","messagePattern":"Checksum mismatch","errorType":"exception","errorClass":"ChecksumError","httpStatus":null,"severity":"error","filePath":"lib/snapshot-manager.js","lineNumber":260,"sourceCode":"\t\tthrow new VersionMismatchError(snapPath, version);\n\t}\n\n\tconst sha256sumOffset = versionOffset + 2;\n\tconst compressedOffset = sha256sumOffset + SHA_256_HASH_LENGTH;\n\tconst compressed = buffer.slice(compressedOffset);\n\n\treturn {\n\t\tversion, compressed, sha256sumOffset, compressedOffset,\n\t};\n}\n\nfunction decodeSnapshots(buffer, snapPath) {\n\tconst {compressed, sha256sumOffset, compressedOffset} = extractCompressedSnapshot(buffer, snapPath);\n\n\tconst sha256sum = crypto.createHash('sha256').update(compressed).digest();\n\tconst expectedSum = buffer.slice(sha256sumOffset, compressedOffset);\n\tif (!sha256sum.equals(expectedSum)) {\n\t\tthrow new ChecksumError(snapPath);\n\t}\n\n\tconst decompressed = zlib.gunzipSync(compressed);\n\treturn decodeCbor(decompressed, {\n\t\tignoreGlobalTags: true,\n\t});\n}\n\nclass Manager {\n\tconstructor(options) {\n\t\tthis.dir = options.dir;\n\t\tthis.recordNewSnapshots = options.recordNewSnapshots;\n\t\tthis.updating = options.updating;\n\t\tthis.relFile = options.relFile;\n\t\tthis.reportFile = options.reportFile;\n\t\tthis.reportPath = options.reportPath;\n\t\tthis.snapFile = options.snapFile;\n\t\tthis.snapPath = options.snapPath;","sourceCodeStart":242,"sourceCodeEnd":278,"githubUrl":"https://github.com/avajs/ava/blob/bbfd946322fdeca2b547a691d947fb4e18c0c67f/lib/snapshot-manager.js#L242-L278","documentation":"Every snapshot file stores a SHA-256 hash of its compressed payload. decodeSnapshots() recomputes the hash of the compressed bytes and compares it to the stored bytes; when they differ the file has been modified or corrupted since it was written, so AVA throws ChecksumError rather than decoding tampered data.","triggerScenarios":"The compressed region of the .snap file was edited after creation (manual edits, patch tools, line-ending conversion altering bytes) or the file was truncated so the stored-hash slice no longer matches the payload.","commonSituations":"Hand-editing snapshot files to 'fix' tests; git filters or editors that rewrite file bytes; merge conflicts resolved incorrectly in a .snap file; corrupted transfer of snapshot artifacts in CI.","solutions":["Regenerate the snapshot: delete the .snap file and run ava --update-snapshots","Restore the original from git (git checkout -- <file>.snap) and ensure no text filters modify it (mark *.snap binary in .gitattributes)","Never merge or hand-edit .snap files; resolve conflicts by regenerating them instead"],"exampleFix":"// before (.gitattributes)\n*.snap text\n// after\n*.snap -text\n*.snap binary","handlingStrategy":"validation","validationCode":"const crypto = require('crypto');\nconst buf = fs.readFileSync(snapPath);\nconst nl = buf.indexOf(0x0A);\nconst versionOffset = nl + 1;\nconst sha256sumOffset = versionOffset + 2;\nconst compressedOffset = sha256sumOffset + 32;\nconst sum = crypto.createHash('sha256').update(buf.slice(compressedOffset)).digest();\nif (!sum.equals(buf.slice(sha256sumOffset, compressedOffset))) {\n  console.warn(`${snapPath} checksum mismatch — file was modified; regenerate`);\n}","typeGuard":"function checksumOk(buffer, sha256sumOffset, compressedOffset) {\n  const crypto = require('crypto');\n  return crypto.createHash('sha256').update(buffer.slice(compressedOffset)).digest()\n    .equals(buffer.slice(sha256sumOffset, compressedOffset));\n}","tryCatchPattern":"try {\n  decodeSnapshots(buffer, snapPath);\n} catch (err) {\n  if (/Checksum mismatch/i.test(err.message)) {\n    // git checkout -- <file>.snap or regenerate with --update-snapshots\n  } else { throw err; }\n}","preventionTips":["Treat .snap files as binary artifacts: never merge or hand-edit them","Add '*.snap -text' to .gitattributes","Resolve snapshot merge conflicts by regenerating, not by editing bytes"],"tags":["snapshots","checksum","integrity"],"backgroundTag":"checksum-mismatch","analyzedSha":"bbfd946322fdeca2b547a691d947fb4e18c0c67f","analyzedAt":"2026-09-02T01:24:43.834Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}