From dccfbb0194e22c03c03015e756bb4e3825f53aa0 Mon Sep 17 00:00:00 2001 From: Jackson Owens Date: Wed, 8 Feb 2023 15:35:50 -0500 Subject: [PATCH] storage: fix UnsafeKey() usage of invalid iterator Previously, CheckSSTConflicts would improperly call UnsafeKey on an exhausted sstIter. This could result in undefined, inconsistent behavior as UnsafeKey may point to arbitrary data once the iterator is exhausted. Informs #94141. Epic: None Release note: None --- pkg/storage/sst.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/storage/sst.go b/pkg/storage/sst.go index 54207dbfdbb5..d2ba10c94eab 100644 --- a/pkg/storage/sst.go +++ b/pkg/storage/sst.go @@ -1077,7 +1077,7 @@ func CheckSSTConflicts( // 2) the ext iterator became invalid // 3) both iterators changed keys and the sst iterator's key is further // ahead. - if extChangedKeys && (!sstChangedKeys || (!extOK && sstOK) || extIter.UnsafeKey().Key.Compare(sstIter.UnsafeKey().Key) < 0) { + if sstOK && extChangedKeys && (!sstChangedKeys || !extOK || extIter.UnsafeKey().Key.Compare(sstIter.UnsafeKey().Key) < 0) { extIter.SeekGE(MVCCKey{Key: sstIter.UnsafeKey().Key}) extOK, extErr = extIter.Valid() }