From 3c540e726e17f2464c62bdb21fafd99601727008 Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Tue, 23 Sep 2025 19:34:56 -0300 Subject: [PATCH] boltdb: fix reusing index key that has less capacity than necessary. --- eventstore/boltdb/helpers.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/eventstore/boltdb/helpers.go b/eventstore/boltdb/helpers.go index b5baaf7..8f0296b 100644 --- a/eventstore/boltdb/helpers.go +++ b/eventstore/boltdb/helpers.go @@ -79,6 +79,7 @@ func (it *iterator) pull(n int, since uint32) { func (it *iterator) seek(key []byte) { fullkey, _ := it.cursor.Seek(key) if fullkey == nil || bytes.Compare(fullkey, key) == 1 { + // we're at the end or passed our desired point, so go back one fullkey, _ = it.cursor.Prev() if fullkey == nil { it.exhausted = true @@ -87,7 +88,11 @@ func (it *iterator) seek(key []byte) { } s := len(fullkey) - it.key = it.key[0 : s-8] + if cap(it.key) >= s-8 { + it.key = it.key[0 : s-8] + } else { + it.key = make([]byte, s-8) + } copy(it.key, fullkey[0:s-8]) copy(it.currIdPtr, fullkey[s-8:]) }