diff --git a/include/flatbuffers/idl.h b/include/flatbuffers/idl.h index a07f62a30b2..f6384894535 100644 --- a/include/flatbuffers/idl.h +++ b/include/flatbuffers/idl.h @@ -473,6 +473,10 @@ inline bool IsStruct(const Type &type) { return type.base_type == BASE_TYPE_STRUCT && type.struct_def->fixed; } +inline bool IsIncompleteStruct(const Type &type) { + return type.base_type == BASE_TYPE_STRUCT && type.struct_def->predecl; +} + inline bool IsTable(const Type &type) { return type.base_type == BASE_TYPE_STRUCT && !type.struct_def->fixed; } diff --git a/src/idl_parser.cpp b/src/idl_parser.cpp index b6b7e9db31a..0d93afbc17c 100644 --- a/src/idl_parser.cpp +++ b/src/idl_parser.cpp @@ -918,6 +918,12 @@ CheckedError Parser::ParseField(StructDef &struct_def) { ECHECK(ParseType(type)); if (struct_def.fixed) { + if (IsIncompleteStruct(type) || + (IsArray(type) && IsIncompleteStruct(type.VectorType()))) { + std::string type_name = IsArray(type) ? type.VectorType().struct_def->name : type.struct_def->name; + return Error(std::string("Incomplete type in struct is not allowed, type name: ") + type_name); + } + auto valid = IsScalar(type.base_type) || IsStruct(type); if (!valid && IsArray(type)) { const auto &elem_type = type.VectorType();