Skip to content

Commit 180ef76

Browse files
committedFeb 25, 2025
fix: prevent panic in FileReader when buffer size exceeds file length.
1 parent 6e726c3 commit 180ef76

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed
 

‎rust/src/file.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ impl FileReader {
110110
///
111111
/// Panics if the requested range is outside of the file
112112
pub async fn read_range_buf(&self, mut buf: &mut [u8], offset: usize) -> Result<()> {
113-
let mut stream = self.read_range_stream(offset, buf.len()).boxed();
113+
let read_length = usize::min(buf.len(), self.file_length() - offset);
114+
let mut stream = self.read_range_stream(offset, read_length).boxed();
114115
while let Some(bytes) = stream.next().await.transpose()? {
115116
buf.put(bytes);
116117
}

0 commit comments

Comments
 (0)
Failed to load comments.