panic in List() method with boltdb backend

Open
#204 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
45/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
go
Domain
database

Research direction

Start with store/boltdb/boltdb.go at the List implementation around line 290 and the supplied TestGetAllKeys reproduction in store/boltdb/boltdb_test.go. Run the regression test against the BoltDB backend and inspect how the empty key/value pair is handled. Done means listing with an empty prefix returns without panicking and the test passes.

Written by the indexing model from the issue text.

Description

If you add the following test to store/boltdb/boltdb_test.go, it will panic:

func TestGetAllKeys(t *testing.T) {
	kv := makeBoltDBClient(t)

	kv.Put("key1", []byte("value1"), &store.WriteOptions{})
	_, err := kv.List("")
	assert.NoError(t, err)
}

This code is trying to get all possible entries from the DB.

Traceback:

panic: runtime error: slice bounds out of range [recovered]
	panic: runtime error: slice bounds out of range

goroutine 5 [running]:
testing.tRunner.func1(0xc42011c0f0)
	/usr/local/go/src/testing/testing.go:742 +0x29d
panic(0x12a6860, 0x14851e0)
	/usr/local/go/src/runtime/panic.go:505 +0x229
github.com/oopcode/libkv/store/boltdb.(*BoltDB).List.func1(0xc4201260e0, 0x1312eb0, 0xc4201260e0)
	/Users/andrei/projects/go/src/github.com/oopcode/libkv/store/boltdb/boltdb.go:289 +0x4ce
go.etcd.io/bbolt.(*DB).View(0xc4201221e0, 0xc420053ea8, 0x0, 0x0)
	/Users/andrei/projects/go/src/go.etcd.io/bbolt/db.go:701 +0x90
github.com/oopcode/libkv/store/boltdb.(*BoltDB).List(0xc42009c370, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
	/Users/andrei/projects/go/src/github.com/oopcode/libkv/store/boltdb/boltdb.go:279 +0x16e
github.com/oopcode/libkv/store/boltdb.TestGetAllKeys(0xc42011c0f0)
	/Users/andrei/projects/go/src/github.com/oopcode/libkv/store/boltdb/boltdb_test.go:151 +0x117
testing.tRunner(0xc42011c0f0, 0x1312e88)
	/usr/local/go/src/testing/testing.go:777 +0xd0
created by testing.(*T).Run
	/usr/local/go/src/testing/testing.go:824 +0x2e0

This line is the one that panics. For some reason the last pair that boltdb driver returns for the "" query is a pair of empty byte slices (empty, not nil); libkv tries to cut its libkvmetadatalen-sized metadata from the returned empty value, which results in the slice bounds out of range error.

I'm not sure whether it's a libkv or boltdb problem, but I thought you might like to know about it.

libkv version is current master, and boltdb version is its latest release.

Dominant language
Go
Stars
847
Forks
204
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from docker/libkv

All issues in docker/libkv

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.