From 308827aec6aa7af5aa3e9c40ed6f366109c5cd19 Mon Sep 17 00:00:00 2001 From: Ulf Lilleengen Date: Fri, 26 Apr 2024 11:07:40 +0200 Subject: [PATCH] ensure writes don't pass max chunk size --- src/page.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/page.rs b/src/page.rs index 9c29301..6a53a85 100644 --- a/src/page.rs +++ b/src/page.rs @@ -434,7 +434,7 @@ impl PageWriter { } pub async fn write(&mut self, flash: &mut F, data: &[u8]) -> Result> { - let max_write = PAGE_SIZE.saturating_sub(self.chunk_offset + ChunkHeader::SIZE + self.chunk_pos); + let max_write = PAGE_SIZE.saturating_sub(self.chunk_offset + ChunkHeader::SIZE + self.chunk_pos).min(MAX_CHUNK_SIZE); let total_n = data.len().min(max_write); if total_n == 0 { return Ok(0);