Skip to content

Commit cc2649a

Browse files
committed
Validate custom type script before loading it
1 parent 15ff450 commit cc2649a

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

editor/scene_tree_dock.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3115,6 +3115,7 @@ void SceneTreeDock::_replace_node(Node *p_node, Node *p_by_node, bool p_keep_pro
31153115
// If we're dealing with a custom node type, we need to create a default instance of the custom type instead of the native type for property comparison.
31163116
if (oldnode->has_meta(SceneStringName(_custom_type_script))) {
31173117
Ref<Script> cts = PropertyUtils::get_custom_type_script(oldnode);
3118+
ERR_FAIL_COND_MSG(cts.is_null(), "Invalid custom type script.");
31183119
default_oldnode = Object::cast_to<Node>(get_editor_data()->script_class_instance(cts->get_global_name()));
31193120
if (default_oldnode) {
31203121
default_oldnode->set_name(cts->get_global_name());

scene/property_utils.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,5 +306,12 @@ Ref<Script> PropertyUtils::get_custom_type_script(const Object *p_object) {
306306
return script_object;
307307
}
308308
#endif
309+
ResourceUID::ID id = ResourceUID::get_singleton()->text_to_id(custom_script);
310+
if (unlikely(id == ResourceUID::INVALID_ID || !ResourceUID::get_singleton()->has_id(id))) {
311+
const_cast<Object *>(p_object)->remove_meta(SceneStringName(_custom_type_script));
312+
ERR_FAIL_V_MSG(Ref<Script>(), vformat("Invalid custom type script UID: %s. Removing.", custom_script.operator String()));
313+
} else {
314+
custom_script = ResourceUID::get_singleton()->get_id_path(id);
315+
}
309316
return ResourceLoader::load(custom_script);
310317
}

0 commit comments

Comments
 (0)