From 0c50eeb227fae51ad2d2697bfe3fbc3628e9fb9b Mon Sep 17 00:00:00 2001 From: Robert Bindar Date: Mon, 1 Apr 2024 15:13:41 +0300 Subject: [PATCH] Fix crash getting file size on non existent blob on Azure. (#4836) 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. --- test/src/unit-vfs.cc | 14 +++++++++++++- tiledb/sm/filesystem/azure.cc | 4 ++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/test/src/unit-vfs.cc b/test/src/unit-vfs.cc index b1c9b8b1f54..939bfd58e6d 100644 --- a/test/src/unit-vfs.cc +++ b/test/src/unit-vfs.cc @@ -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()) { @@ -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)); diff --git a/tiledb/sm/filesystem/azure.cc b/tiledb/sm/filesystem/azure.cc index 8b8f2d88245..ea461f24b40 100644 --- a/tiledb/sm/filesystem/azure.cc +++ b/tiledb/sm/filesystem/azure.cc @@ -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(response.Blobs[0].BlobSize); } - - *nbytes = static_cast(response.Blobs[0].BlobSize); } catch (const ::Azure::Storage::StorageException& e) { error_message = e.Message; }