Skip to content

Commit

Permalink
libsql: error on invalid frame_no on wal read
Browse files Browse the repository at this point in the history
This prevents a potential panic that can happen in our ffi code when it
expects a NonZero value but the input type into the unsafe function is a
u32, meaning the compiler will not enforce the value and will result in
a panic. This changes it so that when the code is called via the sys
crate safe code it will return a sqlite failure.

Closes #1868
  • Loading branch information
LucioFranco committed Dec 6, 2024
1 parent 0c5b83f commit 189e49d
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions libsql/src/local/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,13 @@ impl Connection {
// and more efficient buffer usage for extracting wal frames and spliting them off.
let mut buf = bytes::BytesMut::with_capacity(frame_size);

if frame_no == 0 {
return Err(errors::Error::SqliteFailure(
1,
"frame_no must be non-zero".to_string(),
));
}

let rc = unsafe {
libsql_sys::ffi::libsql_wal_get_frame(
self.handle(),
Expand Down

0 comments on commit 189e49d

Please sign in to comment.