diff --git a/tiledb/core.cc b/tiledb/core.cc index a2b3b4cb4d..ac81eff620 100644 --- a/tiledb/core.cc +++ b/tiledb/core.cc @@ -98,6 +98,10 @@ struct BufferInfo { try { dtype = tiledb_dtype(data_type, cell_val_num); elem_nbytes = tiledb_datatype_size(type); + if (data_nbytes > + static_cast(std::numeric_limits::max())) { + throw std::overflow_error("Data buffer size is too large"); + } data = py::array(py::dtype("uint8"), data_nbytes); offsets = py::array_t(offsets_num); validity = py::array_t(validity_num); diff --git a/tiledb/tests/test_fixes.py b/tiledb/tests/test_fixes.py index af44eefce4..5991326741 100644 --- a/tiledb/tests/test_fixes.py +++ b/tiledb/tests/test_fixes.py @@ -382,6 +382,26 @@ def test_sc62594_buffer_resize(self, array_data): with tiledb.DenseArray(uri) as T: assert_array_equal(array_data, T) + def test_data_buffer_too_large(self): + uri = self.path("test_agis") + dim1 = tiledb.Dim( + name="dim_0", domain=(0, 10000000000), tile=512, dtype=np.int64 + ) + dim2 = tiledb.Dim( + name="dim_1", domain=(0, 10000000000), tile=512, dtype=np.int64 + ) + att = tiledb.Attr(name="data", dtype="int8") + schema = tiledb.ArraySchema( + domain=tiledb.Domain(dim1, dim2), + attrs=(att,), + ) + tiledb.Array.create(uri, schema) + + with tiledb.open(uri, mode="r") as A: + with pytest.raises(OverflowError) as exc: + A[:] + assert "Data buffer size is too large" in str(exc.value) + class SOMA919Test(DiskTestCase): """