Skip to content

Commit

Permalink
Fix crash getting file size on non existent blob on Azure. (#4836)
Browse files Browse the repository at this point in the history
This fixes getting a file size on azure when the blob is non existent.
We would end up not getting an error and trying to read an empty array.

---
TYPE: BUG
DESC: Fix crash getting file size on non existent blob on Azure.
  • Loading branch information
robertbindar authored Apr 1, 2024
1 parent 849052e commit 0c50eeb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
14 changes: 13 additions & 1 deletion test/src/unit-vfs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,19 @@ TEMPLATE_LIST_TEST_CASE("VFS: File I/O", "[vfs][uri][file_io]", AllBackends) {
Config config = set_config_params(disable_multipart, max_parallel_ops);
VFS vfs{&g_helper_stats, &compute_tp, &io_tp, config};

// Getting file_size on a nonexistent blob shouldn't crash on Azure
uint64_t nbytes = 0;
URI non_existent = URI(path.to_string() + "non_existent");
if (path.is_file()) {
#ifdef _WIN32
CHECK(!vfs.file_size(non_existent, &nbytes).ok());
#else
CHECK_THROWS(vfs.file_size(non_existent, &nbytes));
#endif
} else {
CHECK(!vfs.file_size(non_existent, &nbytes).ok());
}

// Set up
bool exists = false;
if (path.is_gcs() || path.is_s3() || path.is_azure()) {
Expand Down Expand Up @@ -494,7 +507,6 @@ TEMPLATE_LIST_TEST_CASE("VFS: File I/O", "[vfs][uri][file_io]", AllBackends) {
CHECK(exists);

// Get file sizes
uint64_t nbytes = 0;
require_tiledb_ok(vfs.file_size(largefile, &nbytes));
CHECK(nbytes == (buffer_size));
require_tiledb_ok(vfs.file_size(smallfile, &nbytes));
Expand Down
4 changes: 2 additions & 2 deletions tiledb/sm/filesystem/azure.cc
Original file line number Diff line number Diff line change
Expand Up @@ -700,9 +700,9 @@ Status Azure::blob_size(const URI& uri, uint64_t* const nbytes) const {

if (response.Blobs.empty()) {
error_message = "Blob does not exist.";
} else {
*nbytes = static_cast<uint64_t>(response.Blobs[0].BlobSize);
}

*nbytes = static_cast<uint64_t>(response.Blobs[0].BlobSize);
} catch (const ::Azure::Storage::StorageException& e) {
error_message = e.Message;
}
Expand Down

0 comments on commit 0c50eeb

Please sign in to comment.