Skip to content

Commit

Permalink
refactor: return entries when read a zero byte instead of returning e…
Browse files Browse the repository at this point in the history
…rror

Signed-off-by: bsbds <[email protected]>
  • Loading branch information
bsbds committed Apr 18, 2024
1 parent 1f22570 commit c22e295
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion crates/curp/src/server/storage/wal/segment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,18 @@ impl WALSegment {
let mut pos = 0;
let mut entries = Vec::new();
while pos < buf.len() {
let (item, n) = decoder.decode(&buf[pos..])?;
let (item, n) = match decoder.decode(&buf[pos..]) {
Ok(decoded) => decoded,
Err(WALError::MaybeEnded) => {
if !buf[pos..].iter().all(|b| *b == 0) {
return Err(WALError::Corrupted(CorruptType::Codec(
"Read zero".to_string(),
)));
}
return Ok(entries);
}
Err(e) => return Err(e),
};
entries.push(item);
pos += n;
}
Expand Down

0 comments on commit c22e295

Please sign in to comment.