From c52a5d08e4ec5e764b08d71c87f5dc3e71e65461 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Kr=C3=BCger?= Date: Thu, 4 Jan 2024 10:22:54 +0100 Subject: [PATCH] fix: Handle greater than file size read limits --- wnfs/src/public/file.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/wnfs/src/public/file.rs b/wnfs/src/public/file.rs index e296309b..c9ac7863 100644 --- a/wnfs/src/public/file.rs +++ b/wnfs/src/public/file.rs @@ -298,8 +298,10 @@ impl PublicFile { len_limit: Option, store: &'a impl BlockStore, ) -> Result> { + let size = self.size(store).await?; let mut reader = self.stream_content(byte_offset, store).await?; if let Some(len) = len_limit { + let len = std::cmp::min(len as u64, size as u64 - byte_offset) as usize; let mut buffer = vec![0; len]; reader.read_exact(&mut buffer).await?; Ok(buffer)