Skip to content

Commit 037e6ed

Browse files
committed
embedded: Enforce strict WAL versioning and buffer check (Phase 3 Refinement)
1 parent 8535372 commit 037e6ed

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

embedded/src/main.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,14 @@ fn main() -> ! {
9999
// Validates `wal.rs` logic.
100100

101101
// Construct WAL Packet:
102-
// Opcode (0x00) | ID (0) | Dim (16) | [1.0, 0.0, -1.0, 0.5 ...]
103-
// 1 + 4 + 2 + (16 * 4) = 7 + 64 = 71 bytes.
104-
let mut wal_data: [u8; 71] = [0; 71];
102+
// Version (1) | Opcode (0x00) | ID (0) | Dim (16) | [1.0, 0.0, -1.0, 0.5 ...]
103+
// 1 + 1 + 4 + 2 + (16 * 4) = 8 + 64 = 72 bytes.
104+
let mut wal_data: [u8; 72] = [0; 72];
105105
let mut idx = 0;
106106

107+
// Version (1)
108+
wal_data[idx] = 0x01; idx += 1;
109+
107110
// Opcode
108111
wal_data[idx] = 0x00; idx += 1;
109112
// ID (0)

embedded/src/wal.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use valori_kernel::types::id::RecordId;
2020
use valori_kernel::types::vector::FxpVector;
2121
use valori_kernel::types::scalar::FxpScalar;
2222

23+
const WAL_VERSION: u8 = 1;
2324
const WAL_OP_INSERT: u8 = 0x00;
2425

2526
fn read_u8(buf: &[u8], offset: &mut usize) -> Result<u8, ()> {
@@ -55,6 +56,13 @@ pub fn apply_wal_log<const M: usize, const D: usize, const N: usize, const E: us
5556
wal_bytes: &[u8]
5657
) -> Result<(), ()> {
5758
let mut offset = 0;
59+
60+
// 1. Check WAL Version
61+
// First byte reserved for format version.
62+
let version = read_u8(wal_bytes, &mut offset)?;
63+
if version != WAL_VERSION {
64+
return Err(()); // Unsupported version
65+
}
5866

5967
// Process until buffer exhausted
6068
while offset < wal_bytes.len() {

0 commit comments

Comments
 (0)