This is an automated email from the ASF dual-hosted git repository.

xuanwo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/opendal.git


The following commit(s) were added to refs/heads/main by this push:
     new 51d61b503 fix(reader): Fix reader fetch with empty ranges (#7286)
51d61b503 is described below

commit 51d61b503612ca9c7b1c32c9f4556a6752da3d85
Author: dentiny <[email protected]>
AuthorDate: Tue Mar 24 01:59:02 2026 -0700

    fix(reader): Fix reader fetch with empty ranges (#7286)
---
 core/core/src/types/read/reader.rs | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/core/core/src/types/read/reader.rs 
b/core/core/src/types/read/reader.rs
index dfc2e9407..576a0390b 100644
--- a/core/core/src/types/read/reader.rs
+++ b/core/core/src/types/read/reader.rs
@@ -144,6 +144,10 @@ impl Reader {
     /// The returning `Buffer` may share the same underlying memory without
     /// any extra copy.
     pub async fn fetch(&self, ranges: Vec<Range<u64>>) -> Result<Vec<Buffer>> {
+        if ranges.is_empty() {
+            return Ok(vec![]);
+        }
+
         let merged_ranges = self.merge_ranges(ranges.clone());
 
         #[derive(Clone)]
@@ -601,4 +605,24 @@ mod tests {
         }
         Ok(())
     }
+
+    #[tokio::test]
+    async fn test_fetch_empty_ranges() -> Result<()> {
+        let op = Operator::new(services::Memory::default()).unwrap().finish();
+        let path = "test_file";
+
+        let content = gen_fixed_bytes(1024);
+        op.write(path, content.clone())
+            .await
+            .expect("write must succeed");
+
+        let reader = op.reader(path).await.unwrap();
+        let result = reader
+            .fetch(vec![])
+            .await
+            .expect("fetch with empty ranges must not panic");
+        assert!(result.is_empty());
+
+        Ok(())
+    }
 }

Reply via email to