Skip to content

fix(buffer): make buffer capacity atleast defaultCapacity#273

Merged
NamanJain8 merged 2 commits intomasterfrom
naman/default-cap
May 4, 2021
Merged

fix(buffer): make buffer capacity atleast defaultCapacity#273
NamanJain8 merged 2 commits intomasterfrom
naman/default-cap

Conversation

@NamanJain8
Copy link
Contributor

@NamanJain8 NamanJain8 commented May 4, 2021

z.Buffer when initialized with sz < 8, it may cause crash as the buffer size is less than offset.

panic: runtime error: slice bounds out of range [:8] with capacity 7 [recovered]
	panic: runtime error: slice bounds out of range [:8] with capacity 7

goroutine 6 [running]:
testing.tRunner.func1.2(0xa09780, 0xc00084e090)
	/usr/local/go/src/testing/testing.go:1143 +0x332
testing.tRunner.func1(0xc000001b00)
	/usr/local/go/src/testing/testing.go:1146 +0x4b6
panic(0xa09780, 0xc00084e090)
	/usr/local/go/src/runtime/panic.go:965 +0x1b9
github.com/dgraph-io/ristretto/z.(*Buffer).Grow(0xc0067f60e0, 0xf)
	/home/algod/go/src/github.com/dgraph-io/ristretto/z/buffer.go:230 +0x7c5
github.com/dgraph-io/ristretto/z.(*Buffer).Write(...)
	/home/algod/go/src/github.com/dgraph-io/ristretto/z/buffer.go:495
github.com/dgraph-io/ristretto/z.(*sortHelper).sortSmall(0xc000135840, 0x8, 0x17)
	/home/algod/go/src/github.com/dgraph-io/ristretto/z/buffer.go:328 +0x305
github.com/dgraph-io/ristretto/z.(*Buffer).SortSliceBetween(0xc0001fe070, 0x8, 0x17, 0xa61b90)
	/home/algod/go/src/github.com/dgraph-io/ristretto/z/buffer.go:448 +0x453
github.com/dgraph-io/ristretto/z.(*Buffer).SortSlice(...)
	/home/algod/go/src/github.com/dgraph-io/ristretto/z/buffer.go:411
github.com/dgraph-io/badger/v3.(*DB).DropPrefixNonBlocking.func1(0xc000156001, 0xae8df0, 0xc00001c140)
	/home/algod/go/src/github.com/dgraph-io/badger/db.go:1866 +0x155
github.com/dgraph-io/badger/v3.(*DB).DropPrefixNonBlocking.func2(0xc0008561f8, 0x2, 0x2, 0xc0001fe070, 0x1)
	/home/algod/go/src/github.com/dgraph-io/badger/db.go:1935 +0x21f
github.com/dgraph-io/badger/v3.(*DB).DropPrefixNonBlocking(0xc000123b00, 0xc000850a80, 0x1, 0x1, 0x0, 0x0)
	/home/algod/go/src/github.com/dgraph-io/badger/db.go:1940 +0x24c
github.com/dgraph-io/badger/v3.TestDropPrefixNonBlockingNoError(0xc000001b00)
	/home/algod/go/src/github.com/dgraph-io/badger/db2_test.go:1150 +0x49c
testing.tRunner(0xc000001b00, 0xa62018)
	/usr/local/go/src/testing/testing.go:1193 +0xef
created by testing.(*T).Run
	/usr/local/go/src/testing/testing.go:1238 +0x2b3

This change is Reviewable

Copy link
Contributor

@manishrjain manishrjain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Reviewed 2 of 2 files at r1.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @jarifibrahim)

@NamanJain8 NamanJain8 merged commit 0bf2acd into master May 4, 2021
@NamanJain8 NamanJain8 deleted the naman/default-cap branch May 4, 2021 19:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants