Skip to content
This repository has been archived by the owner on Aug 1, 2024. It is now read-only.
This repository has been archived by the owner on Aug 1, 2024. It is now read-only.

Setting blob metadata with empty string VALUE but valid key throws exception #828

Open

Description

Which service(blob, file, queue, table) does this issue concern?

Blob

Which version of the SDK was used?

9.3

Which platform are you using? (ex: .NET Core 2.1)

Net Core 2.1

What problem was encountered?

An exception (parameter cannot be empty string) when calling blobReference.SetMetadataAsync() to set blob metadata to the dictionary that I set on the blob reference.

I set the metadata properties like this

blobReference.Metadata.Add("PropertyName", value);

if the value of the parameter is null or empty string, an exception is thrown:

Microsoft.WindowsAzure.Storage.StorageException: The argument must not be empty string. ---> System.ArgumentException: The argument must not be empty string.
at Microsoft.WindowsAzure.Storage.Shared.Protocol.HttpRequestMessageFactory.AddMetadata(StorageRequestMessage request, String name, String value)
at Microsoft.WindowsAzure.Storage.Shared.Protocol.HttpRequestMessageFactory.AddMetadata(StorageRequestMessage request, IDictionary2 metadata) at Microsoft.WindowsAzure.Storage.Blob.CloudBlob.<>c__DisplayClass135_0.<SetMetadataImpl>b__0(RESTCommand1 cmd, Uri uri, UriQueryBuilder builder, HttpContent cnt, Nullable1 serverTimeout, OperationContext ctx) at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteAsyncInternal[T](RESTCommand1 cmd, IRetryPolicy policy, OperationContext operationContext, CancellationToken token)
--- End of inner exception stack trace ---
at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteAsyncInternal[T](RESTCommand`1 cmd, IRetryPolicy policy, OperationContext operationContext, CancellationToken token)

How can we reproduce the problem in the simplest way?

Get a cloud blob blob reference and call:
blobReference.Metadata.Add("PropertyName", null);
blobReference.SetMetadataAsync();

or

blobReference.Metadata.Add("PropertyName", "");
blobReference.SetMetadataAsync();

Have you found a mitigation/solution?

I believe this is a bug the the code here: https://github.com/Azure/azure-storage-net/blob/master/Lib/Common/Shared/Protocol/HttpRequestMessageFactory.cs#L203

it checks for the value being null but should be checking the name for null instead. It later goes on to construct the header name from the name so clearly was intended to check the name rather than value

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions