Panic : Slice Range Out Of Bound. InitIndex Crashed

What version of Go are you using (go version)?

$ go version 1.20

What operating system are you using?


What version of Badger are you using?


Does this issue reproduce with the latest master?


Steps to Reproduce the issue

While compacting/ Compressing, huge memory is consuming and process is getting killed by the following error

What Badger options were set?

// func to create a key value db
func NewKeyValueDB(dataDir, name string) (*KeyValueDB, error) {
db, err := badger.Open(badger.DefaultOptions(dataDir + “/” + name))
if err != nil {
return nil, err
return &KeyValueDB{
DB: db,
dataDir: dataDir,
name: name,
}, nil

What did you do?

What did you expect to see?

No error.

What did you see instead?

panic: runtime error: slice bounds out of range [-4169358568:] [recovered]
        panic: runtime error: slice bounds out of range [-4169358568:]
    == Recovering from initIndex crash ==
    File Info: [ID: 95, Size: 69121215, Zeros: 0]
    isEnrypted: false checksumLen: 4238479779 
    == Recovered ==
    goroutine 6932842 [running]:*Table).initBiggestAndSmallest.func1.1()
        /data/badger_broadband/badger_grpc/vendor/ +0xa8
    panic({0xba9420, 0xc4324db2d8})
        /usr/local/go/src/runtime/panic.go:884 +0x212*MmapFile).Bytes(...)
        /data/badger_broadband/badger_grpc/vendor/*Table).readNoFail(0xd0a740?, 0xc4a7b68810?, 0xbfe74d?)
        /data/badger_broadband/badger_grpc/vendor/ +0xd0*Table).initBiggestAndSmallest.func1()
        /data/badger_broadband/badger_grpc/vendor/ +0x2ff
    panic({0xba9420, 0xc4324db2c0})
        /usr/local/go/src/runtime/panic.go:884 +0x212*MmapFile).Bytes(...)
        /data/badger_broadband/badger_grpc/vendor/*Table).readNoFail(0x6?, 0x0?, 0x9?)
        /data/badger_broadband/badger_grpc/vendor/ +0xd0*Table).initIndex(0xc47e194180)
        /data/badger_broadband/badger_grpc/vendor/ +0x109*Table).initBiggestAndSmallest(0xc47e194180)
        /data/badger_broadband/badger_grpc/vendor/ +0x7f, {0x0, 0x1, 0x1000000, 0xf33333, 0x0, 0x3f847ae147ae147b, 0x1000, 0x0, 0x1, ...})
        /data/badger_broadband/badger_grpc/vendor/ +0x278{0xc167146b80, 0x33}, 0xccef5a4090)
        /data/badger_broadband/badger_grpc/vendor/ +0x305*levelsController).subcompact.func4(0xccef5a4090, 0xc025c8b6e0?)
        /data/badger_broadband/badger_grpc/vendor/ +0x11b
    created by*levelsController).subcompact
        /data/badger_broadband/badger_grpc/vendor/ +0x707