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 0fcc9c3c90 fix(core): skip unreadable discovered directories in glob 
listing (#8967)
0fcc9c3c90 is described below

commit 0fcc9c3c909b433d259e18bd11803ef77dd3cb4b
Author: Chitral Verma <[email protected]>
AuthorDate: Tue Nov 24 07:20:21 2026 +0530

    fix(core): skip unreadable discovered directories in glob listing (#8967)
---
 core/core/src/layers/glob.rs       | 11 +++++++++++
 core/core/src/layers/glob/tests.rs | 28 ++++++++++++++++++++++++++++
 core/services/fs/src/lister.rs     | 33 +++++++++++++++++++++++++++++++++
 3 files changed, 72 insertions(+)

diff --git a/core/core/src/layers/glob.rs b/core/core/src/layers/glob.rs
index af9c25f8e8..612c9f42ae 100644
--- a/core/core/src/layers/glob.rs
+++ b/core/core/src/layers/glob.rs
@@ -179,6 +179,7 @@ impl Service for GlobService {
                 path: directory,
                 positions: vec![position],
                 lister: None,
+                discovered: false,
             }]
         } else {
             Vec::new()
@@ -198,6 +199,8 @@ struct Directory {
     path: String,
     positions: Vec<usize>,
     lister: Option<oio::Lister>,
+    /// Found while listing a parent rather than requested by the caller.
+    discovered: bool,
 }
 
 impl Directory {
@@ -242,6 +245,13 @@ impl List for GuidedLister {
                     self.directories.pop();
                     continue;
                 }
+                // Like recursive listings, skip discovered directories that 
cannot
+                // be read. The starting directory still reports the error.
+                Err(err) if err.kind() == ErrorKind::PermissionDenied && 
directory.discovered => {
+                    log::warn!("glob listing skipped directory {}: {err}", 
directory.path);
+                    self.directories.pop();
+                    continue;
+                }
                 Err(err) => return Err(err),
             };
             if !entry.path().starts_with(&self.prefix) {
@@ -264,6 +274,7 @@ impl List for GuidedLister {
                     path: entry.path().to_owned(),
                     positions,
                     lister: None,
+                    discovered: true,
                 });
             }
             if matches {
diff --git a/core/core/src/layers/glob/tests.rs 
b/core/core/src/layers/glob/tests.rs
index 75fd2d6185..a1f6f78dc2 100644
--- a/core/core/src/layers/glob/tests.rs
+++ b/core/core/src/layers/glob/tests.rs
@@ -102,6 +102,29 @@ async fn 
guided_listing_skips_literal_parents_and_keeps_page_size() -> Result<()
     Ok(())
 }
 
+#[tokio::test]
+async fn guided_listing_skips_unreadable_discovered_directories() -> 
Result<()> {
+    let inner = Arc::new(ListFixture {
+        entries: vec![
+            oio::Entry::new("locked/", MetadataBuilder::dir().build()),
+            oio::Entry::new("open/", MetadataBuilder::dir().build()),
+            oio::Entry::new("open/a.jpg", MetadataBuilder::file(0).build()),
+        ],
+        denied: Some("locked/"),
+        ..ListFixture::new(&[])
+    });
+    let op = Operator::from_parts(OperationContext::default(), 
inner.clone()).layer(GlobLayer);
+    let entries = op.list_with("/").glob("*/*.jpg").await?;
+    assert_eq!(
+        entries.iter().map(Entry::path).collect::<Vec<_>>(),
+        ["open/a.jpg"]
+    );
+    // The directory the caller asked for still reports the error.
+    let err = op.list_with("locked/").glob("*.jpg").await.unwrap_err();
+    assert_eq!(err.kind(), ErrorKind::PermissionDenied);
+    Ok(())
+}
+
 #[tokio::test]
 async fn filtering_preserves_versions_and_delete_markers_at_the_same_path() -> 
Result<()> {
     let entries = [
@@ -178,6 +201,7 @@ struct ListFixture {
     requests: Mutex<Vec<(String, OpList)>>,
     entries: Vec<oio::Entry>,
     native_glob: bool,
+    denied: Option<&'static str>,
 }
 
 impl ListFixture {
@@ -189,6 +213,7 @@ impl ListFixture {
                 .map(|path| oio::Entry::new(path, 
MetadataBuilder::file(0).build()))
                 .collect(),
             native_glob: false,
+            denied: None,
         }
     }
 }
@@ -219,6 +244,9 @@ impl Service for ListFixture {
 
     fn list(&self, _: &OperationContext, path: &str, args: OpList) -> 
Result<Self::Lister> {
         self.requests.lock().unwrap().push((path.to_owned(), args));
+        if self.denied == Some(path) {
+            return Err(Error::new(ErrorKind::PermissionDenied, "denied"));
+        }
         Ok(TestLister(self.entries.clone().into()))
     }
 
diff --git a/core/services/fs/src/lister.rs b/core/services/fs/src/lister.rs
index f874720949..6c1df2457c 100644
--- a/core/services/fs/src/lister.rs
+++ b/core/services/fs/src/lister.rs
@@ -366,6 +366,39 @@ mod tests {
             ErrorKind::PermissionDenied
         );
     }
+
+    #[tokio::test]
+    async fn glob_skips_unreadable_child() {
+        let root = tempfile::tempdir().unwrap();
+        let locked = root.path().join("data/locked");
+        fs::create_dir_all(&locked).unwrap();
+        fs::create_dir_all(root.path().join("data/open")).unwrap();
+        fs::write(locked.join("a.jpg"), b"data").unwrap();
+        fs::write(root.path().join("data/open/b.jpg"), b"data").unwrap();
+        let op = 
Operator::new(Fs::default().root(root.path().to_str().unwrap())).unwrap();
+        let permissions = fs::metadata(&locked).unwrap().permissions();
+        fs::set_permissions(&locked, 
fs::Permissions::from_mode(0o000)).unwrap();
+
+        // Privileged processes can read the directory even with mode 000.
+        match fs::read_dir(&locked) {
+            Ok(_) => {
+                fs::set_permissions(&locked, permissions).unwrap();
+                return;
+            }
+            Err(err) => assert_eq!(err.kind(), 
std::io::ErrorKind::PermissionDenied),
+        }
+
+        let any_depth = op.list_with("/").glob("data/**/*.jpg").await;
+        let one_level = op.list_with("/").glob("data/*/*.jpg").await;
+        let direct = op.list_with("data/locked/").glob("*.jpg").await;
+        fs::set_permissions(&locked, permissions).unwrap();
+
+        for entries in [any_depth.unwrap(), one_level.unwrap()] {
+            let paths: Vec<_> = entries.iter().map(|entry| 
entry.path()).collect();
+            assert_eq!(paths, ["data/open/b.jpg"]);
+        }
+        assert_eq!(direct.unwrap_err().kind(), ErrorKind::PermissionDenied);
+    }
 }
 
 #[cfg(test)]

Reply via email to