diff --git a/Makefile b/Makefile index 4359725d0..3252209df 100644 --- a/Makefile +++ b/Makefile @@ -9,7 +9,7 @@ NAME = CUBELinux # release. The base version stays in VERSION/PATCHLEVEL/SUBLEVEL above (visible in # `make kernelversion`), while `uname -r` and /lib/modules report the CUBELinux # release, with any -dirty or SCM suffix still appended by setlocalversion. -CUBELINUX_VERSION = CUBELinux.0.4 +CUBELINUX_VERSION = CUBELinux.0.5 # *DOCUMENTATION* # To see a list of typical targets execute "make help" diff --git a/drivers/cube/cubelinux_store.rs b/drivers/cube/cubelinux_store.rs index 7a5690e35..f4c5430b3 100644 --- a/drivers/cube/cubelinux_store.rs +++ b/drivers/cube/cubelinux_store.rs @@ -634,17 +634,17 @@ fn apply_log(log: &[u8], merged: &mut Merged) -> Result, &'static st let key = &log[off + 37..off + 61]; word.copy_from_slice(&log[off + 61..off + 65]); let len = u32::from_le_bytes(word) as usize; - off += ENTRY_FIXED; - if off + len > log.len() { + let frame_end = start + ENTRY_FIXED + len; + if frame_end > log.len() { break; } // The checksum covers space, key, length and value, so a corrupted entry is // stopped at rather than applied. - if crc32(&log[start + 5..off + len]) != crc { + if crc32(&log[start + 5..frame_end]) != crc { break; } - let value = &log[off..off + len]; - off += len; + let value = &log[start + ENTRY_FIXED..frame_end]; + off = frame_end; merged .add(space, key, value, op == 2) .map_err(|_| "out-of-memory")?; @@ -812,14 +812,17 @@ fn log_valid_len(log: &[u8]) -> Result { let crc = u32::from_le_bytes(word); word.copy_from_slice(&log[off + 61..off + 65]); let len = u32::from_le_bytes(word) as usize; - off += ENTRY_FIXED; - if off + len > log.len() { + // Only a validated entry moves the append point. Advancing first and checking after + // counts a torn entry as part of the prefix, so the next append lands *after* the + // corruption and buries it — the opposite of the rule that a torn tail is overwritten. + let frame_end = start + ENTRY_FIXED + len; + if frame_end > log.len() { break; } - if crc32(&log[start + 5..off + len]) != crc { + if crc32(&log[start + 5..frame_end]) != crc { break; } - off += len; + off = frame_end; } Ok(off) }