From dc4455d819a9590d1dc9aabcc3fd0ec1f07b8bba Mon Sep 17 00:00:00 2001 From: Bojidar Marinov Date: Thu, 16 Jan 2020 15:53:34 +0200 Subject: Validate instances of objects before trying to check their type in GDScript Fixes #27582 --- modules/gdscript/gdscript_function.h | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/modules/gdscript/gdscript_function.h b/modules/gdscript/gdscript_function.h index 236ca720a2..ad95ebc543 100644 --- a/modules/gdscript/gdscript_function.h +++ b/modules/gdscript/gdscript_function.h @@ -76,14 +76,17 @@ struct GDScriptDataType { if (p_variant.get_type() != Variant::OBJECT) { return false; } + Object *obj = p_variant.operator Object *(); - if (obj) { - if (!ClassDB::is_parent_class(obj->get_class_name(), native_type)) { - // Try with underscore prefix - StringName underscore_native_type = "_" + native_type; - if (!ClassDB::is_parent_class(obj->get_class_name(), underscore_native_type)) { - return false; - } + if (!obj || !ObjectDB::instance_validate(obj)) { + return false; + } + + if (!ClassDB::is_parent_class(obj->get_class_name(), native_type)) { + // Try with underscore prefix + StringName underscore_native_type = "_" + native_type; + if (!ClassDB::is_parent_class(obj->get_class_name(), underscore_native_type)) { + return false; } } return true; @@ -96,7 +99,12 @@ struct GDScriptDataType { if (p_variant.get_type() != Variant::OBJECT) { return false; } + Object *obj = p_variant.operator Object *(); + if (!obj || !ObjectDB::instance_validate(obj)) { + return false; + } + Ref