Skip to content

Commit 4d9247b

Browse files
committed
libsql: Validate generation in get_remote_info()
If server returns zero as generation, lets return an error from get_remote_info() instead of making metadata inconsistent.
1 parent a68c3b3 commit 4d9247b

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

libsql/src/sync.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ pub enum SyncError {
6868
InvalidLocalGeneration(u32, u32),
6969
#[error("invalid local state: {0}")]
7070
InvalidLocalState(String),
71+
#[error("invalid remote state: {0}")]
72+
InvalidRemoteState(String),
7173
#[error("server returned invalid length of frames: {0}")]
7274
InvalidPullFrameBytes(usize),
7375
}
@@ -614,8 +616,10 @@ impl SyncContext {
614616
.await
615617
.map_err(SyncError::HttpBody)?;
616618

617-
let info = serde_json::from_slice(&body).map_err(SyncError::JsonDecode)?;
618-
619+
let info: InfoResult = serde_json::from_slice(&body).map_err(SyncError::JsonDecode)?;
620+
if info.current_generation == 0 {
621+
return Err(SyncError::InvalidRemoteState("generation is 0".to_string()).into());
622+
}
619623
Ok(info)
620624
}
621625

0 commit comments

Comments
 (0)