dgraph-io/badger · critical
invalid index length in footer. Data corrupted
Error message
invalid index length in footer. Data corrupted
What it means
The index length read from the footer must be positive and must fit within the bytes remaining between the footer and the start of the file. Zero is always invalid (every table has at least one block, hence a non-empty index); too-large values indicate corruption.
Source
Thrown at table/table.go:463
// Read checksum.
expectedChk := &pb.Checksum{}
readPos -= checksumLen
buf = t.readNoFail(readPos, checksumLen)
if err := proto.Unmarshal(buf, expectedChk); err != nil {
return nil, err
}
// Read index size from the footer.
if readPos < 4 {
return nil, errors.New("invalid table size in footer. Data corrupted")
}
readPos -= 4
buf = t.readNoFail(readPos, 4)
t.indexLen = int(y.BytesToU32(buf))
// A table always has at least one block, so a zero indexLen is always
// corruption, and the index must fit in the bytes remaining before readPos.
if t.indexLen <= 0 || t.indexLen > readPos {
return nil, errors.New("invalid index length in footer. Data corrupted")
}
// Read index.
readPos -= t.indexLen
t.indexStart = readPos
data := t.readNoFail(readPos, t.indexLen)
if err := y.VerifyChecksum(data, expectedChk); err != nil {
return nil, y.Wrapf(err, "failed to verify checksum for table: %s", t.Filename())
}
index, err := t.readTableIndex()
if err != nil {
return nil, err
}
if !t.shouldDecrypt() {
// If there's no encryption, this points to the mmap'ed buffer.
t._index = indexView on GitHub (pinned to 2a001d466f)
Solutions
- Quarantine the offending SST file and let Badger continue with remaining tables
- Restore the file from a verified backup and compare checksums
- Confirm all files were produced by the same Badger major version
- If corruption is widespread, restore the whole directory or rebuild via db.Load
Example fix
// before: retrying db.Open on the same corrupt dir
// after: move corrupt table aside, reopen
tableSize, _ := t.Size()
_ = tableSize
os.Rename("data/000012.sst", "data/000012.sst.corrupt")
db, err := badger.Open(opt) Defensive patterns
Strategy: fallback
Validate before calling
// inspect footer indexLen yourself before trusting the dir
idxLen := binary.LittleEndian.Uint32(tail[8:12])
if idxLen == 0 || int(idxLen) > len(data)-12 {
os.Rename(tablePath, tablePath+".corrupt") // let DB open without it
} Prevention
- Quarantine individual corrupt tables instead of blocking DB open
- Keep verified backups of the data directory
- Confirm uniform Badger versions across all writers (shared NFS etc.)
When it happens
Trigger: Opening a table whose footer's indexLen field is zero, negative (uint32 overflow), or exceeds the remaining readable bytes — corrupted footer, garbage tail bytes, or cross-version format mismatch.
Common situations: Tail-overwritten SSTs after disk issues; files copied from an incompatible format; interrupted writes producing zero-filled footer regions.
Related errors
- invalid table size in footer. Data corrupted
- invalid checksum length in footer. Data corrupted
- initIndex crashed: %v %s
- failed to read block offset from index. Data corrupted
- block out of index
AI-assisted analysis of dgraph-io/badger@2a001d466f (2026-09-05).
Data as JSON: /api/errors/7c4a0f43be9ba003.
Report an issue: GitHub.