From 06f5ded03829b575f5e9f2e7b89b8f8052d653b5 Mon Sep 17 00:00:00 2001 From: Thomas Krijnen Date: Mon, 29 Sep 2025 11:29:52 +0200 Subject: [PATCH] Don't crash on missing schema when loading rdb --- src/ifcparse/IfcParse.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/ifcparse/IfcParse.cpp b/src/ifcparse/IfcParse.cpp index 8f3b74f4b6..a92b9b1347 100644 --- a/src/ifcparse/IfcParse.cpp +++ b/src/ifcparse/IfcParse.cpp @@ -1381,11 +1381,13 @@ IfcFile::IfcFile(const std::string& path, filetype ty, bool readonly) storage_.emplace<0>(); good_ = file_open_status::READ_ERROR; } else { - std::get(storage_).read_schema(schema_); - - byid_ = decltype(byid_)(&std::get(storage_).instance_by_name_); - byref_excl_ = decltype(byref_excl_)(&std::get(storage_).byref_excl_); - byguid_ = decltype(byguid_)(&std::get(storage_).byguid_); + if (std::get(storage_).read_schema(schema_)) { + byid_ = decltype(byid_)(&std::get(storage_).instance_by_name_); + byref_excl_ = decltype(byref_excl_)(&std::get(storage_).byref_excl_); + byguid_ = decltype(byguid_)(&std::get(storage_).byguid_); + } else { + good_ = file_open_status::UNSUPPORTED_SCHEMA; + } } // byidentity_ = decltype(byidentity_)(&std::get(storage_).instance_cache_); } else { @@ -2896,7 +2898,11 @@ bool IfcParse::impl::rocks_db_file_storage::read_schema(const IfcParse::schema_d db->Get(rocksdb::ReadOptions{}, key, &value); std::vector strings; if (::impl::deserialize(this, value, strings) && strings.size() == 1) { - schema = schema_by_name(strings[0]); + try { + schema = schema_by_name(strings[0]); + } catch (IfcException&) { + return false; + } return true; } #endif