Skip to content

Commit 6237e57

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 7fbef83 commit 6237e57

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

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
}
@@ -616,8 +618,10 @@ impl SyncContext {
616618
.await
617619
.map_err(SyncError::HttpBody)?;
618620

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

0 commit comments

Comments
 (0)