Skip to content

Commit 2fe4a91

Browse files
committed
datastore: fix out-of-bounds index in snapshots BTree
1 parent 5dc37dc commit 2fe4a91

File tree

1 file changed

+6
-0
lines changed
  • silkworm/db/datastore/snapshots/btree

1 file changed

+6
-0
lines changed

silkworm/db/datastore/snapshots/btree/btree.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ std::optional<BytesOrByteView> BTree::get(ByteView key, const KeyValueIndex& ind
118118
}
119119
const uint64_t median = (left_index + right_index) >> 1;
120120
const auto lookup_result = index.lookup_key_value(median, key);
121+
if (!lookup_result) {
122+
return std::nullopt;
123+
}
121124
const auto [cmp, optional_v] = *lookup_result;
122125
if (cmp == 0) {
123126
SILKWORM_ASSERT(optional_v);
@@ -130,6 +133,9 @@ std::optional<BytesOrByteView> BTree::get(ByteView key, const KeyValueIndex& ind
130133
}
131134
}
132135
const auto lookup_result = index.lookup_key_value(left_index, key);
136+
if (!lookup_result) {
137+
return std::nullopt;
138+
}
133139
const auto [cmp, optional_v] = *lookup_result;
134140
if (cmp != 0) {
135141
return std::nullopt;

0 commit comments

Comments
 (0)