From d6e45952d0db1c7d1374fd311fcb128753624d87 Mon Sep 17 00:00:00 2001 From: Miao Xia Date: Thu, 9 Feb 2023 14:12:26 +0800 Subject: [PATCH] Add more limitation on searhPage To avoid goroutine stack exceeds 1000000000-byte limit. Some records may result to func `cursor.searh()` and `cursor.searchPage` recusively called. Fixes: #402 Signed-off-by: Miao Xia --- cursor.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/cursor.go b/cursor.go index 5dafb0cac..2260e5deb 100644 --- a/cursor.go +++ b/cursor.go @@ -317,11 +317,14 @@ func (c *Cursor) searchPage(key []byte, p *page) { index := sort.Search(int(p.count), func(i int) bool { // TODO(benbjohnson): Optimize this range search. It's a bit hacky right now. // sort.Search() finds the lowest index where f() != -1 but we need the highest index. - ret := bytes.Compare(inodes[i].key(), key) - if ret == 0 { - exact = true + if bytes.HasPrefix(inodes[i].key(), key) { + ret := bytes.Compare(inodes[i].key(), key) + if ret == 0 { + exact = true + } + return ret != -1 } - return ret != -1 + return false }) if !exact && index > 0 { index--