From 8164eb32c3b142db8766fc891707b691c15fde00 Mon Sep 17 00:00:00 2001 From: metsw24-max Date: Wed, 25 Mar 2026 17:51:55 +0000 Subject: [PATCH 1/6] Add null check for type_vec in VerifyVector function --- src/reflection.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/reflection.cpp b/src/reflection.cpp index e77d21b04b..f31235ca1f 100644 --- a/src/reflection.cpp +++ b/src/reflection.cpp @@ -155,6 +155,7 @@ static bool VerifyVector(flatbuffers::Verifier& v, if (!vec) return true; auto type_vec = table.GetPointer*>(vec_field.offset() - sizeof(voffset_t)); + if (!type_vec) return false; if (!v.VerifyVector(type_vec)) return false; if (type_vec->size() != vec->size()) return false; for (uoffset_t j = 0; j < vec->size(); j++) { From e26d319a4b849294ce39f25c2fe8936723e6a2db Mon Sep 17 00:00:00 2001 From: metsw24-max Date: Sun, 29 Mar 2026 14:57:58 +0000 Subject: [PATCH 2/6] updated --- src/reflection.cpp | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/reflection.cpp b/src/reflection.cpp index f31235ca1f..9c08bf4551 100644 --- a/src/reflection.cpp +++ b/src/reflection.cpp @@ -155,7 +155,6 @@ static bool VerifyVector(flatbuffers::Verifier& v, if (!vec) return true; auto type_vec = table.GetPointer*>(vec_field.offset() - sizeof(voffset_t)); - if (!type_vec) return false; if (!v.VerifyVector(type_vec)) return false; if (type_vec->size() != vec->size()) return false; for (uoffset_t j = 0; j < vec->size(); j++) { @@ -379,18 +378,28 @@ std::string GetAnyValueS(reflection::BaseType type, const uint8_t* data, void ForAllFields(const reflection::Object* object, bool reverse, std::function func) { - std::vector field_to_id_map; - field_to_id_map.resize(object->fields()->size()); + if (!object->fields()) return; + + const auto kSentinel = static_cast(-1); + std::vector field_to_id_map(object->fields()->size(), kSentinel); // Create the mapping of field ID to the index into the vector. for (uint32_t i = 0; i < object->fields()->size(); ++i) { auto field = object->fields()->Get(i); - field_to_id_map[field->id()] = i; + const auto id = field->id(); + + if (id >= field_to_id_map.size()) continue; + + field_to_id_map[id] = i; } for (size_t i = 0; i < field_to_id_map.size(); ++i) { - func(object->fields()->Get( - field_to_id_map[reverse ? field_to_id_map.size() - i + 1 : i])); + const auto idx = + field_to_id_map[reverse ? field_to_id_map.size() - i - 1 : i]; + + if (idx == kSentinel) continue; + + func(object->fields()->Get(idx)); } } @@ -801,4 +810,4 @@ bool VerifySizePrefixed(const reflection::Schema& schema, /*required=*/true); } -} // namespace flatbuffers +} // namespace flatbuffers \ No newline at end of file From 5f42eae609ebbe2c8b1e144575c8210bfb118678 Mon Sep 17 00:00:00 2001 From: metsw24-max Date: Sun, 29 Mar 2026 16:13:08 +0000 Subject: [PATCH 3/6] updated --- src/reflection.cpp | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/src/reflection.cpp b/src/reflection.cpp index 9c08bf4551..e7575f183c 100644 --- a/src/reflection.cpp +++ b/src/reflection.cpp @@ -155,6 +155,7 @@ static bool VerifyVector(flatbuffers::Verifier& v, if (!vec) return true; auto type_vec = table.GetPointer*>(vec_field.offset() - sizeof(voffset_t)); + if (!type_vec) return false; if (!v.VerifyVector(type_vec)) return false; if (type_vec->size() != vec->size()) return false; for (uoffset_t j = 0; j < vec->size(); j++) { @@ -378,28 +379,18 @@ std::string GetAnyValueS(reflection::BaseType type, const uint8_t* data, void ForAllFields(const reflection::Object* object, bool reverse, std::function func) { - if (!object->fields()) return; - - const auto kSentinel = static_cast(-1); - std::vector field_to_id_map(object->fields()->size(), kSentinel); + std::vector field_to_id_map; + field_to_id_map.resize(object->fields()->size()); // Create the mapping of field ID to the index into the vector. for (uint32_t i = 0; i < object->fields()->size(); ++i) { auto field = object->fields()->Get(i); - const auto id = field->id(); - - if (id >= field_to_id_map.size()) continue; - - field_to_id_map[id] = i; + field_to_id_map[field->id()] = i; } for (size_t i = 0; i < field_to_id_map.size(); ++i) { - const auto idx = - field_to_id_map[reverse ? field_to_id_map.size() - i - 1 : i]; - - if (idx == kSentinel) continue; - - func(object->fields()->Get(idx)); + func(object->fields()->Get( + field_to_id_map[reverse ? field_to_id_map.size() - i + 1 : i])); } } From 91c65b822d939a24dca6a4172f2bd57706bdf4e5 Mon Sep 17 00:00:00 2001 From: metsw24-max Date: Sun, 29 Mar 2026 16:30:53 +0000 Subject: [PATCH 4/6] updated --- src/reflection.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/reflection.cpp b/src/reflection.cpp index e7575f183c..daa3658fd5 100644 --- a/src/reflection.cpp +++ b/src/reflection.cpp @@ -155,8 +155,8 @@ static bool VerifyVector(flatbuffers::Verifier& v, if (!vec) return true; auto type_vec = table.GetPointer*>(vec_field.offset() - sizeof(voffset_t)); - if (!type_vec) return false; if (!v.VerifyVector(type_vec)) return false; + if (!type_vec) return true; if (type_vec->size() != vec->size()) return false; for (uoffset_t j = 0; j < vec->size(); j++) { // get union type from the prev field From 5744ea029e37d09356ee1d1d4647be19b344fe20 Mon Sep 17 00:00:00 2001 From: metsw24-max Date: Sun, 29 Mar 2026 17:03:27 +0000 Subject: [PATCH 5/6] updated --- src/reflection.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/reflection.cpp b/src/reflection.cpp index daa3658fd5..4316a8569c 100644 --- a/src/reflection.cpp +++ b/src/reflection.cpp @@ -155,8 +155,8 @@ static bool VerifyVector(flatbuffers::Verifier& v, if (!vec) return true; auto type_vec = table.GetPointer*>(vec_field.offset() - sizeof(voffset_t)); - if (!v.VerifyVector(type_vec)) return false; if (!type_vec) return true; + if (!v.VerifyVector(type_vec)) return false; if (type_vec->size() != vec->size()) return false; for (uoffset_t j = 0; j < vec->size(); j++) { // get union type from the prev field From 31b1c2a5977cce07a564dfe48d6e0b1f05b75d7c Mon Sep 17 00:00:00 2001 From: metsw24-max Date: Thu, 2 Apr 2026 03:02:48 +0000 Subject: [PATCH 6/6] updated --- src/reflection.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/reflection.cpp b/src/reflection.cpp index 4316a8569c..e7575f183c 100644 --- a/src/reflection.cpp +++ b/src/reflection.cpp @@ -155,7 +155,7 @@ static bool VerifyVector(flatbuffers::Verifier& v, if (!vec) return true; auto type_vec = table.GetPointer*>(vec_field.offset() - sizeof(voffset_t)); - if (!type_vec) return true; + if (!type_vec) return false; if (!v.VerifyVector(type_vec)) return false; if (type_vec->size() != vec->size()) return false; for (uoffset_t j = 0; j < vec->size(); j++) {