Skip to content

Commit df9c036

Browse files
add invalid commit floor corruption detection
1 parent 7ee0826 commit df9c036

3 files changed

Lines changed: 13 additions & 0 deletions

File tree

storage/src/qmdb/any/db.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,11 @@ where
524524
.expect("commit should exist");
525525
let last_commit = reader.read(last_commit_loc).await?;
526526
let inactivity_floor_loc = last_commit.has_floor().expect("should be a commit");
527+
if *inactivity_floor_loc > last_commit_loc {
528+
return Err(crate::qmdb::Error::DataCorrupted(
529+
"inactivity floor exceeds last commit",
530+
));
531+
}
527532
if let Some(known_inactivity_floor) = known_inactivity_floor {
528533
(*known_inactivity_floor..*inactivity_floor_loc)
529534
.for_each(|_| callback(false, None));

storage/src/qmdb/immutable/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,9 @@ where
208208
let inactivity_floor_loc = last_op
209209
.has_floor()
210210
.expect("last operation should be a commit with floor");
211+
if inactivity_floor_loc > last_commit_loc {
212+
return Err(Error::DataCorrupted("inactivity floor exceeds last commit"));
213+
}
211214

212215
// Replay the log from the inactivity floor to build the snapshot.
213216
build_snapshot_from_log::<F, _, _, _>(

storage/src/qmdb/store/db.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,11 @@ where
370370
let reader = log.reader().await;
371371
let op = reader.read(*last_commit_loc).await?;
372372
let inactivity_floor_loc = op.has_floor().expect("last op should be a commit");
373+
if inactivity_floor_loc > last_commit_loc {
374+
return Err(crate::qmdb::Error::DataCorrupted(
375+
"inactivity floor exceeds last commit",
376+
));
377+
}
373378
let active_keys =
374379
build_snapshot_from_log(inactivity_floor_loc, &reader, &mut snapshot, |_, _| {})
375380
.await?;

0 commit comments

Comments
 (0)