disallow circular struct references (#8851)

* detect and fail for circular struct dependencies

* pr comments

* pr comment
This commit is contained in:
Justin Davis
2026-02-04 10:15:05 -05:00
committed by GitHub
parent 4623cfa4bc
commit ea0a73d168
4 changed files with 60 additions and 1 deletions

View File

@@ -395,13 +395,20 @@ struct FieldDef : public Definition {
};
struct StructDef : public Definition {
enum class CycleStatus {
NotChecked,
InProgress,
Checked,
};
StructDef()
: fixed(false),
predecl(true),
sortbysize(true),
has_key(false),
minalign(1),
bytesize(0) {}
bytesize(0),
cycle_status{CycleStatus::NotChecked} {}
void PadLastField(size_t min_align) {
auto padding = PaddingBytes(bytesize, min_align);
@@ -423,6 +430,8 @@ struct StructDef : public Definition {
size_t minalign; // What the whole object needs to be aligned to.
size_t bytesize; // Size if fixed.
CycleStatus cycle_status; // used for determining if we have circular references
flatbuffers::unique_ptr<std::string> original_location;
std::vector<voffset_t> reserved_ids;
};
@@ -1101,6 +1110,8 @@ class Parser : public ParserState {
// others includes.
std::vector<IncludedFile> GetIncludedFiles() const;
bool HasCircularStructDependency();
private:
class ParseDepthGuard;