kopia/kopia · critical
invalid data - corrupted
Error message
invalid data - corrupted
What it means
After recomputing the HMAC-SHA256 over the payload, VerifyAndStrip compares it with the trailing signature using hmac.Equal. When the two differ, the data fails authentication and the error 'invalid data - corrupted' is returned; the payload is never emitted to the output buffer.
Solutions
- Verify the configured HMAC secret matches the one used when the data was written.
- Delete the corrupted cache/blob entry and re-fetch it from the source.
- Check storage hardware/backend for corruption; run repository consistency checks.
Example fix
// before
err := hmac.VerifyAndStrip(entry, secret, out) // fails: corrupted
// after
err := hmac.VerifyAndStrip(entry, secret, out)
if err != nil {
os.Remove(cachePath) // drop bad entry, refetch
entry = refetchBlob(blobID)
err = hmac.VerifyAndStrip(entry, secret, out)
} Defensive patterns
Strategy: try-catch
Try / catch
err := hmac.VerifyAndStrip(data, secret, out)
if err != nil {
if strings.Contains(err.Error(), "corrupted") {
// authenticated failure: drop entry, refetch from canonical source
os.Remove(cachePath)
return refetchAndVerify(id)
}
return err
} Prevention
- Never bypass or ignore VerifyAndStrip errors — the payload must not be used on failure.
- Keep the HMAC secret in sync between writer and reader (single config source).
- Enable storage-level checksums/scrubbing to detect bit rot early.
- Never share a cache directory between repositories with different secrets.
When it happens
Trigger: Calling VerifyAndStrip on blob data whose content or trailing 32-byte signature was modified — bit rot, truncated-then-overwritten cache files, wrong secret used for verification, or mixing data written with a different key.
Common situations: Failing disk or flaky storage backend corrupting cached blobs; rotating/incorrect HMAC secret in configuration; a cache directory shared between repositories with different secrets.
Understand the failure class
Background: Checksum mismatch errors: "checksum verification failed", "digest mismatch", "expected vs actual checksum" — what they mean and how to fix them — this error's family across 41 libraries.
Related errors
AI-assisted analysis of kopia/kopia@82495e54b5 (2026-09-07).
Data as JSON: /api/errors/5ae234f6004c46c4.
Report an issue: GitHub.
Appendix: source
Thrown at internal/hmac/hmac.go:54
if _, err := io.CopyN(io.MultiWriter(h, output), r, int64(p)); err != nil {
return errors.Wrap(err, "error hashing")
}
var sigBuf, actualSignature [sha256.Size]byte
validSignature := h.Sum(sigBuf[:0])
n, err := r.Read(actualSignature[:])
if err != nil || n != sha256.Size {
return errors.Wrap(err, "error reading signature")
}
if hmac.Equal(validSignature, actualSignature[:]) {
return nil
}
return errors.New("invalid data - corrupted")
}
View on GitHub (pinned to 82495e54b5)