mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-08 14:15:17 +00:00
disallow circular struct references (#8851)
* detect and fail for circular struct dependencies * pr comments * pr comment
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user