Skip to content

Commit

Permalink
Fix segfault in ArraySchema::check (#4787)
Browse files Browse the repository at this point in the history
Previously we weren't accounting for when enumerations weren't loaded
and a check was performed. This lead to attempts to dereference the
nullptr when the enumeration hadn't been loaded.

Given that enumerations are only unloaded when reading an array, that
means these checks were already run when the schema was written so
ignoring them here is fine since they're just enforcing a maximum size
constraint.

---
TYPE: BUG
DESC: Fix segfault in ArraySchema::check
  • Loading branch information
davisp authored Mar 5, 2024
1 parent 0a349d6 commit 9bd16ba
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
12 changes: 12 additions & 0 deletions test/src/unit-enumerations.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1452,6 +1452,18 @@ TEST_CASE_METHOD(
REQUIRE_THROWS_WITH(schema->check(cfg_), matcher);
}

TEST_CASE_METHOD(
EnumerationFx,
"ArraySchema - No Segfault on Check",
"[enumeration][array-scehma][size-check]") {
create_array();
auto array = get_array(QueryType::READ);
auto schema = array->array_schema_latest_ptr();
// Schema has unloaded enumerations at this point. Make sure that check
// doesn't segfault.
REQUIRE_NOTHROW(schema->check(cfg_));
}

TEST_CASE_METHOD(
EnumerationFx,
"ArraySchema - Many Large Enumerations",
Expand Down
6 changes: 6 additions & 0 deletions tiledb/sm/array_schema/array_schema.cc
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,12 @@ void ArraySchema::check_enumerations(const Config& cfg) const {

uint64_t total_size = 0;
for (const auto& pair : enumeration_map_) {
if (!pair.second) {
// We don't have an Array instance at this point so the best we can do
// is just avoid segfaulting when we attempt to check with unloaded
// enumerations.
continue;
}
uint64_t size = pair.second->data().size() + pair.second->offsets().size();
if (size > max_size.value()) {
throw ArraySchemaException(
Expand Down

0 comments on commit 9bd16ba

Please sign in to comment.