Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't segfault in ArraySchema::dump #4583

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions test/regression/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ if (TILEDB_CPP_API)
list(APPEND SOURCES targets/sc-29682.cc)
list(APPEND SOURCES targets/sc-33480.cc)
list(APPEND SOURCES targets/sc-35424.cc)
list(APPEND SOURCES targets/sc-38300.cc)
endif()

add_executable(tiledb_regression
Expand Down
59 changes: 59 additions & 0 deletions test/regression/targets/sc-38300.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#include <chrono>
#include <climits>
#include <thread>

#include <tiledb/tiledb>
#include <tiledb/tiledb_experimental>

#include <test/support/tdb_catch.h>

using namespace tiledb;

static void create_array(const std::string& array_uri);
static void dump_schema(const std::string& array_uri);

TEST_CASE(
"Don't segfault in ArraySchema::dump with unloaded enumerations",
"[array-schema][enumeration][bug][sc38300]") {
std::string array_uri = "test_array_schema_dump";

// Test setup
create_array(array_uri);
dump_schema(array_uri);
}

void create_array(const std::string& array_uri) {
Context ctx;

auto obj = Object::object(ctx, array_uri);
if (obj.type() != Object::Type::Invalid) {
Object::remove(ctx, array_uri);
}

auto dim = Dimension::create<int32_t>(ctx, "d", {{0, 1024}});

Domain dom(ctx);
dom.add_dimension(dim);

std::vector<std::string> values = {"fred", "wilma", "barney", "pebbles"};
auto enmr = Enumeration::create(ctx, "flintstones", values);

auto attr = Attribute::create<int32_t>(ctx, "a");
AttributeExperimental::set_enumeration_name(ctx, attr, "flintstones");

ArraySchema schema(ctx, TILEDB_SPARSE);
ArraySchemaExperimental::add_enumeration(ctx, schema, enmr);
schema.set_order({{TILEDB_ROW_MAJOR, TILEDB_ROW_MAJOR}})
.set_domain(dom)
.add_attribute(attr);

Array::create(array_uri, schema);
}

void dump_schema(const std::string& array_uri) {
Context ctx;
Array array(ctx, array_uri, TILEDB_READ);
array.schema().dump();
ArrayExperimental::load_all_enumerations(ctx, array);
array.schema().dump();
}
10 changes: 9 additions & 1 deletion tiledb/sm/array_schema/array_schema.cc
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,15 @@ void ArraySchema::dump(FILE* out) const {

for (auto& enmr_iter : enumeration_map_) {
fprintf(out, "\n");
enmr_iter.second->dump(out);
if (enmr_iter.second != nullptr) {
enmr_iter.second->dump(out);
} else {
std::stringstream ss;
ss << "### Enumeration ###" << std::endl;
ss << "- Name: " << enmr_iter.first << std::endl;
ss << "- Loaded: false" << std::endl;
fprintf(out, "%s", ss.str().c_str());
}
}

for (auto& label : dimension_labels_) {
Expand Down
4 changes: 4 additions & 0 deletions tiledb/sm/array_schema/attribute.cc
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,10 @@ void Attribute::dump(FILE* out) const {
fprintf(out, "\n");
fprintf(out, "- Data ordering: %s", data_order_str(order_).c_str());
}
if (enumeration_name_.has_value()) {
fprintf(out, "\n");
fprintf(out, "- Enumeration name: %s", enumeration_name_.value().c_str());
}
fprintf(out, "\n");
}

Expand Down
1 change: 1 addition & 0 deletions tiledb/sm/array_schema/enumeration.cc
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@ void Enumeration::dump(FILE* out) const {
std::stringstream ss;
ss << "### Enumeration ###" << std::endl;
ss << "- Name: " << name_ << std::endl;
ss << "- Loaded: true" << std::endl;
ss << "- Type: " << datatype_str(type_) << std::endl;
ss << "- Cell Val Num: " << cell_val_num_ << std::endl;
ss << "- Ordered: " << (ordered_ ? "true" : "false") << std::endl;
Expand Down
Loading