Azure / Azure/azure-sdk-for-cpp

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

Open
#6,607 4 comments 0 reactions 1 assignee Claimed by @chiangvincent View on GitHub
customer-reported question Storage
Dominant language
C++
Stars
205
Forks
172
Avg merge
1d 15m
Merged PRs (30d)
33

Description

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`

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.