Skip to content

Commit

Permalink
storage: fix UnsafeKey() usage of invalid iterator
Browse files Browse the repository at this point in the history
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 cockroachdb#94141.
Epic: None
Release note: None
  • Loading branch information
jbowens committed Feb 9, 2023
1 parent 8ee03c4 commit 3d26608
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/storage/sst.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down

0 comments on commit 3d26608

Please sign in to comment.