Skip to content

Commit 189e49d

Browse files
committed
libsql: error on invalid frame_no on wal read
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
1 parent 0c5b83f commit 189e49d

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

libsql/src/local/connection.rs

+7
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,13 @@ impl Connection {
462462
// and more efficient buffer usage for extracting wal frames and spliting them off.
463463
let mut buf = bytes::BytesMut::with_capacity(frame_size);
464464

465+
if frame_no == 0 {
466+
return Err(errors::Error::SqliteFailure(
467+
1,
468+
"frame_no must be non-zero".to_string(),
469+
));
470+
}
471+
465472
let rc = unsafe {
466473
libsql_sys::ffi::libsql_wal_get_frame(
467474
self.handle(),

0 commit comments

Comments
 (0)