From c2557cc432c874635e66a374b49e972a5494bdc7 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Sat, 27 Nov 2021 16:18:18 +0000 Subject: [PATCH] azureblob: fix crash with SAS URL and no container - fixes #5820 Before this change attempting NewObject on a SAS URL's root would crash the Azure SDK. This change detects that using the code from this previous fix f7404f52e7654d12 azureblob: fix crash when listing outside a SAS URL's root - fixes #4851 And returns not object not found instead. It also prevents things being uploaded to the root of the SAS URL which also crashes the Azure SDK. --- backend/azureblob/azureblob.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/backend/azureblob/azureblob.go b/backend/azureblob/azureblob.go index 8a3b0b36d..5dc7f73af 100644 --- a/backend/azureblob/azureblob.go +++ b/backend/azureblob/azureblob.go @@ -1461,6 +1461,10 @@ func (o *Object) clearMetaData() { // o.size // o.md5 func (o *Object) readMetaData() (err error) { + container, _ := o.split() + if !o.fs.containerOK(container) { + return fs.ErrorObjectNotFound + } if !o.modTime.IsZero() { return nil } @@ -1653,7 +1657,10 @@ func (o *Object) Update(ctx context.Context, in io.Reader, src fs.ObjectInfo, op return errCantUpdateArchiveTierBlobs } } - container, _ := o.split() + container, containerPath := o.split() + if container == "" || containerPath == "" { + return fmt.Errorf("can't upload to root - need a container") + } err = o.fs.makeContainer(ctx, container) if err != nil { return err