From 4f06fcdc9ededfc801dccbeb24343523b3a04f28 Mon Sep 17 00:00:00 2001 From: Dan Heuckeroth Date: Thu, 8 Jan 2026 17:06:57 -0500 Subject: [PATCH 1/4] Check for valid length in mock flash --- src/mock_flash.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mock_flash.rs b/src/mock_flash.rs index cb224fc..abc7f02 100644 --- a/src/mock_flash.rs +++ b/src/mock_flash.rs @@ -86,7 +86,7 @@ impl fn validate_operation(offset: u32, length: usize) -> Result, MockFlashError> { let offset = offset as usize; - if (offset % Self::READ_SIZE) != 0 { + if (offset % Self::READ_SIZE) != 0 || length == 0 || length % BYTES_PER_WORD != 0 { Err(MockFlashError::NotAligned) } else if offset > Self::CAPACITY_BYTES || offset + length > Self::CAPACITY_BYTES { Err(MockFlashError::OutOfBounds) From 241a7b5ac0425d962c6624727da9d7e55dde85d2 Mon Sep 17 00:00:00 2001 From: Dan Heuckeroth Date: Thu, 8 Jan 2026 16:59:16 -0500 Subject: [PATCH 2/4] Avoid issuing empty writes for small items --- src/item.rs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/item.rs b/src/item.rs index 3553cc4..760f185 100644 --- a/src/item.rs +++ b/src/item.rs @@ -290,14 +290,16 @@ impl<'d> Item<'d> { }; let data_address = ItemHeader::data_address::(address); - flash - .write(data_address, data_block) - .await - .map_err(|e| Error::Storage { - value: e, - #[cfg(feature = "_test")] - backtrace: std::backtrace::Backtrace::capture(), - })?; + if !data_block.is_empty() { + flash + .write(data_address, data_block) + .await + .map_err(|e| Error::Storage { + value: e, + #[cfg(feature = "_test")] + backtrace: std::backtrace::Backtrace::capture(), + })?; + } if !data_left.is_empty() { let mut buffer = AlignedBuf([0; MAX_WORD_SIZE]); From 90c9a38617520ab51d76f5e6f041cc75543310aa Mon Sep 17 00:00:00 2001 From: Dan Heuckeroth Date: Thu, 8 Jan 2026 18:56:10 -0500 Subject: [PATCH 3/4] Avoid issuing empty reads also --- src/item.rs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/item.rs b/src/item.rs index 760f185..fc3ce77 100644 --- a/src/item.rs +++ b/src/item.rs @@ -141,14 +141,16 @@ impl ItemHeader { let mut retry = false; loop { - flash - .read(data_address, &mut data_buffer[..read_len]) - .await - .map_err(|e| Error::Storage { - value: e, - #[cfg(feature = "_test")] - backtrace: std::backtrace::Backtrace::capture(), - })?; + if read_len != 0 { + flash + .read(data_address, &mut data_buffer[..read_len]) + .await + .map_err(|e| Error::Storage { + value: e, + #[cfg(feature = "_test")] + backtrace: std::backtrace::Backtrace::capture(), + })?; + } let data = &data_buffer[..self.length as usize]; let data_crc = adapted_crc32(data); From a142c6ad224b0de4c1515c4d95ca92eb9789069a Mon Sep 17 00:00:00 2001 From: Dan Heuckeroth Date: Thu, 8 Jan 2026 18:59:57 -0500 Subject: [PATCH 4/4] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1e5e1f5..0342b07 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ - Optimized cache a little bit which saves ~200 bytes binary size in example - Add heap-backed cache types when the `alloc` feature is active. This gets rid of some (const) generics and allows you to create a cache with dynamic length. +- Added checks to avoid trying to write or read zero bytes of data to/from the flash This release is 'disk'-compatible with 6.0