flatbuffers
flatbuffers copied to clipboard
[TS] flatc silently crashing (segmentation fault)
Minimal replication schema:
namespace SomeNamespace;
enum Colour : byte { Red, Green }
struct SubStruct {
colour: Colour;
}
struct BaseStruct {
test: SubStruct;
}
When running flatc.exe --ts test.fbs
, the command takes a little longer to run than normal and fails to complete. There are no outputs in the console, but the files are not completely generated, and echo %ERRORLEVEL%
returns -1073741819
. I'm not sure what I'm doing wrong. It seems to be related to the enum in the sub-struct.
OS: Windows 11 Version 10.0.22621 Build 22621 flatc version: 24.3.25
Compiling from source and running the same test under Ubuntu 22.04 LTS gives a segfault. I have no clue what I'm doing with gdb but this is what I get with a backtrace:
(gdb) backtrace
#0 0x00005555555ab30e in std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >::size() const ()
#1 0x000055555570bc95 in flatbuffers::(anonymous namespace)::ImportDefinition flatbuffers::ts::TsGenerator::AddImport<flatbuffers::EnumDef>(std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, flatbuffers::(anonymous namespace)::ImportDefinition, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, flatbuffers::(anonymous namespace)::ImportDefinition> > >&, flatbuffers::Definition const&, flatbuffers::EnumDef const&) ()
#2 0x00005555557142fd in flatbuffers::ts::TsGenerator::GenTypeName(std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, flatbuffers::(anonymous namespace)::ImportDefinition, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, flatbuffers::(anonymous namespace)::ImportDefinition> > >&, flatbuffers::Definition const&, flatbuffers::Type const&, bool, bool) ()
#3 0x0000555555714a7b in flatbuffers::ts::TsGenerator::GenStructArgs(std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, flatbuffers::(anonymous namespace)::ImportDefinition, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, flatbuffers::(anonymous namespace)::ImportDefinition> > >&, flatbuffers::StructDef const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) ()
#4 0x0000555555714a12 in flatbuffers::ts::TsGenerator::GenStructArgs(std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, flatbuffers::(anonymous namespace)::ImportDefinition, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, flatbuffers::(anonymous namespace)::ImportDefinition> > >&, flatbuffers::StructDef const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) ()
#5 0x000055555572422e in flatbuffers::ts::TsGenerator::GenStruct(flatbuffers::Parser const&, flatbuffers::StructDef&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*, std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, flatbuffers::(anonymous namespace)::ImportDefinition, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, flatbuffers::(anonymous namespace)::ImportDefinition> > >&) ()
#6 0x0000555555710ba7 in flatbuffers::ts::TsGenerator::generateStructs() ()
#7 0x000055555570fff2 in flatbuffers::ts::TsGenerator::generate() ()
#8 0x000055555570ad70 in flatbuffers::GenerateTS(flatbuffers::Parser const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) ()
#9 0x000055555570b0dd in flatbuffers::(anonymous namespace)::TsCodeGenerator::GenerateCode(flatbuffers::Parser const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) ()
#10 0x00005555557d5c97 in flatbuffers::FlatCompiler::GenerateCode(flatbuffers::FlatCOptions const&, flatbuffers::Parser&) ()
#11 0x00005555557d6b2c in flatbuffers::FlatCompiler::Compile(flatbuffers::FlatCOptions const&) ()
#12 0x00005555557e9ead in main ()
I don't have time to investigate this myself but I hope it can be fixed quickly anyway 😊
I was able to reproduce this on Linux.
Building with -c dbg
results in SIGILL rather than SIGSEGV.
Program received signal SIGILL, Illegal instruction.
0x0000555555b725ff in flatbuffers::ts::TsGenerator::AddImport<flatbuffers::EnumDef> (this=0x7fffffffac90, imports=..., dependent=..., dependency=...)
at third_party/flatbuffers/src/idl_gen_ts.cpp:904
904 const auto &dep_comps = dependent.defined_namespace->components;
(gdb) where
#0 0x0000555555b725ff in flatbuffers::ts::TsGenerator::AddImport<flatbuffers::EnumDef> (this=0x7fffffffac90, imports=..., dependent=..., dependency=...)
at third_party/flatbuffers/src/idl_gen_ts.cpp:904
#1 0x0000555555b84187 in flatbuffers::ts::TsGenerator::GenTypeName (this=0x7fffffffac90, imports=..., owner=..., type=..., input=true, allowNull=false)
at third_party/flatbuffers/src/idl_gen_ts.cpp:559
#2 0x0000555555b858a8 in flatbuffers::ts::TsGenerator::GenStructArgs (this=0x7fffffffac90, imports=..., struct_def=..., arguments=0x7fffffff9570, nameprefix=...)
at third_party/flatbuffers/src/idl_gen_ts.cpp:620
#3 0x0000555555b85688 in flatbuffers::ts::TsGenerator::GenStructArgs (this=0x7fffffffac90, imports=..., struct_def=..., arguments=0x7fffffff9570, nameprefix=...)
at third_party/flatbuffers/src/idl_gen_ts.cpp:616
#4 0x0000555555b7fe04 in flatbuffers::ts::TsGenerator::GenStruct (this=0x7fffffffac90, parser=..., struct_def=..., code_ptr=0x7fffffffab88, imports=...)
at third_party/flatbuffers/src/idl_gen_ts.cpp:1964
#5 0x0000555555b8e780 in flatbuffers::ts::TsGenerator::generateStructs (this=0x7fffffffac90) at third_party/flatbuffers/src/idl_gen_ts.cpp:235
#6 0x0000555555b8df63 in flatbuffers::ts::TsGenerator::generate (this=0x7fffffffac90) at third_party/flatbuffers/src/idl_gen_ts.cpp:115
#7 0x0000555555b6e6ac in flatbuffers::GenerateTS (parser=..., path=..., file_name=...) at third_party/flatbuffers/src/idl_gen_ts.cpp:2182
#8 0x0000555555b6e209 in flatbuffers::(anonymous namespace)::TsCodeGenerator::GenerateCode (this=0x522bbfe06220, parser=..., path=..., filename=...)
at third_party/flatbuffers/src/idl_gen_ts.cpp:2206
#9 0x00005555558f749b in flatbuffers::FlatCompiler::GenerateCode (this=0x7fffffffd950, options=..., conform_parser=...) at third_party/flatbuffers/src/flatc.cpp:966
#10 0x00005555558f8325 in flatbuffers::FlatCompiler::Compile (this=0x7fffffffd950, options=...) at third_party/fla899 const std::string symbols_expression = GenSymbolExpression(
#11 0x00005555558b99cf in main (argc=3, argv=0x7fffffffda98) at third_party/flatbuffers/src/flatc_main.cpp:183
(gdb) list
900 dependency, has_name_clash, import_name, name, object_name);
901
902 std::string bare_file_path;
903 std::string rel_file_path;
904 const auto &dep_comps = dependent.defined_namespace->components;
905 for (size_t i = 0; i < dep_comps.size(); i++) {
906 rel_file_path += i == 0 ? ".." : (kPathSeparator + std::string(".."));
907 }
908 if (dep_comps.size() == 0) { rel_file_path += "."; }
tbuffers/src/flatc.cpp:1063