Skip to content

Commit b988125

Browse files
authored
fix: prevent incorrect range queries when searching for a page version (#1528)
It is important to verify that the data we got from Foundation DB matches with what we want, since we are doing a range query. for example, say we searched for ('db_name42', 10, 20). If this page does not exist, then it could match with ('db_name41', 10, 20) or with ('db_name42', 9, 20) since it does lexicographic search.
1 parent b24ae4b commit b988125

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

libsql-storage-server/src/fdb_store.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,18 @@ impl FrameStore for FDBFrameStore {
136136
.await;
137137
let unpacked: (String, String, u32, u64) =
138138
unpack(&result.unwrap().to_vec()).expect("failed to decode");
139-
tracing::info!("got the frame_no = {:?}", unpacked);
140-
return Some(unpacked.3);
139+
// It is important to verify that the data we got from Foundation DB matches with what we
140+
// want, since we are doing a range query.
141+
//
142+
// for example, say we searched for ('db_name42', 10, 20). If this page does not exist, then
143+
// it could match with ('db_name41', 10, 20) or with ('db_name42', 9, 20) since it does
144+
// lexicographic search.
145+
if (namespace, "pf", page_no) == (&unpacked.0, &unpacked.1, unpacked.2) {
146+
tracing::info!("got the frame_no = {:?}", unpacked);
147+
Some(unpacked.3)
148+
} else {
149+
None
150+
}
141151
}
142152

143153
async fn frame_page_no(&self, namespace: &str, frame_no: u64) -> Option<u32> {

0 commit comments

Comments
 (0)