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

f7404f52e7 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.
This commit is contained in:
Nick Craig-Wood 2021-11-27 16:18:18 +00:00
parent 3425726c50
commit c2557cc432

View File

@ -1461,6 +1461,10 @@ func (o *Object) clearMetaData() {
// o.size // o.size
// o.md5 // o.md5
func (o *Object) readMetaData() (err error) { func (o *Object) readMetaData() (err error) {
container, _ := o.split()
if !o.fs.containerOK(container) {
return fs.ErrorObjectNotFound
}
if !o.modTime.IsZero() { if !o.modTime.IsZero() {
return nil return nil
} }
@ -1653,7 +1657,10 @@ func (o *Object) Update(ctx context.Context, in io.Reader, src fs.ObjectInfo, op
return errCantUpdateArchiveTierBlobs 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) err = o.fs.makeContainer(ctx, container)
if err != nil { if err != nil {
return err return err