Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

azureblob: fix crash when listing outside a SAS URL's root - fixes #4851

Nick Craig-Woodf7404f52e765
diff --git a/backend/azureblob/azureblob.go b/backend/azureblob/azureblob.go
index bffc2f550..20331183c 100644
--- a/backend/azureblob/azureblob.go
+++ b/backend/azureblob/azureblob.go
@@ -776,8 +776,26 @@ func (f *Fs) itemToDirEntry(remote string, object *azblob.BlobItemInternal, isDi
return o, nil
}
+// Check to see if this is a limited container and the container is not found
+func (f *Fs) containerOK(container string) bool {
+ if !f.isLimited {
+ return true
+ }
+ f.cntURLcacheMu.Lock()
+ defer f.cntURLcacheMu.Unlock()
+ for limitedContainer := range f.cntURLcache {
+ if container == limitedContainer {
+ return true
+ }
+ }
+ return false
+}
+
// listDir lists a single directory
func (f *Fs) listDir(ctx context.Context, container, directory, prefix string, addContainer bool) (entries fs.DirEntries, err error) {
+ if !f.containerOK(container) {
+ return nil, fs.ErrorDirNotFound
+ }
err = f.list(ctx, container, directory, prefix, addContainer, false, f.opt.ListChunkSize, func(remote string, object *azblob.BlobItemInternal, isDirectory bool) error {
entry, err := f.itemToDirEntry(remote, object, isDirectory)
if err != nil {
@@ -886,6 +904,9 @@ func (f *Fs) ListR(ctx context.Context, dir string, callback fs.ListRCallback) (
f.cache.MarkOK(container)
}
} else {
+ if !f.containerOK(container) {
+ return fs.ErrorDirNotFound
+ }
err = listR(container, directory, f.rootDirectory, f.rootContainer == "")
if err != nil {
return err