Skip to content

Exception thrown due to missing 'x-ms-creation-time' header in Azure Storage SDK (C++) #6607

Open
@MustafaDewaswala

Description

@MustafaDewaswala

Hello Team,

I'm currently using Microsoft Azure OneLake for data storage and accessing files programmatically using C++. Below are the Azure SDK for C++ packages and versions I'm working with:

azure-core-cpp: 1.15.0

azure-identity-cpp: 1.11.0

azure-storage-blobs-cpp: 12.13.0

azure-storage-common-cpp: 12.10.0

azure-storage-files-datalake-cpp: 12.12.0

Issue Description:

The ListPaths() function on the DataLakeDirectoryClient works as expected for listing directory contents.
However, when I attempt to download files using the DownloadTo() method on the DataLakeFileClient, an exception is thrown during execution.

Caught std::out_of_range: map::at

Root Cause (Debug Info):

Upon debugging, I traced the error to the following file: rest_client.cpp

Here is the relevant snippet:

auto pRawResponse = pipeline.Send(request, context);
auto httpStatusCode = pRawResponse->GetStatusCode();
if (!(httpStatusCode == Core::Http::HttpStatusCode::Ok
      || httpStatusCode == Core::Http::HttpStatusCode::PartialContent))
{
    throw StorageException::CreateFromResponse(std::move(pRawResponse));
}

Models::DownloadBlobResult response;
response.BodyStream = pRawResponse->ExtractBodyStream();

if (pRawResponse->GetHeaders().count("Last-Modified") != 0)
{
    response.Details.LastModified = DateTime::Parse(
        pRawResponse->GetHeaders().at("Last-Modified"), Azure::DateTime::DateFormat::Rfc1123);
}

// **The following line throws exception if header is missing**
response.Details.CreatedOn = DateTime::Parse(
    pRawResponse->GetHeaders().at("x-ms-creation-time"),
    Azure::DateTime::DateFormat::Rfc1123);

The issue arises because the "x-ms-creation-time" header is accessed using .at() without checking for its existence. If this header is not present in the response (as in my case), it throws a std::out_of_range exception.
Suggested Fix:

Before accessing "x-ms-creation-time", add a check similar to "Last-Modified":

if (pRawResponse->GetHeaders().count("x-ms-creation-time") != 0)
{
    response.Details.CreatedOn = DateTime::Parse(
        pRawResponse->GetHeaders().at("x-ms-creation-time"),
        Azure::DateTime::DateFormat::Rfc1123);
}

Could you please review this issue and confirm if this fix can be added in a future SDK release? Also, it would be helpful to know in which upcoming version this fix might be available.

Thank you for your support!
Suggested Labels: bug, azure-sdk, C++, storage

Metadata

Metadata

Assignees

Labels

StorageStorage Service (Queues, Blobs, Files)customer-reportedIssues that are reported by GitHub users external to the Azure organization.questionThe issue doesn't require a change to the product in order to be resolved. Most issues start as that

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions