From 1cfbf16e320ca9bdadd9c24eb1d2d68b25369ba6 Mon Sep 17 00:00:00 2001 From: Pimyn Girgis Date: Tue, 2 Dec 2025 12:28:10 +0000 Subject: executor: update flatbuffers Update flatbuffers to v23.5.26, which matches the compiler version in the new env container. --- executor/_include/flatbuffers/verifier.h | 85 +++++++++++++++++++------------- 1 file changed, 50 insertions(+), 35 deletions(-) (limited to 'executor/_include/flatbuffers/verifier.h') diff --git a/executor/_include/flatbuffers/verifier.h b/executor/_include/flatbuffers/verifier.h index 87d3f54a5..de1146be9 100644 --- a/executor/_include/flatbuffers/verifier.h +++ b/executor/_include/flatbuffers/verifier.h @@ -34,12 +34,16 @@ class Verifier FLATBUFFERS_FINAL_CLASS { bool check_alignment = true; // If true, run verifier on nested flatbuffers bool check_nested_flatbuffers = true; + // The maximum size of a buffer. + size_t max_size = FLATBUFFERS_MAX_BUFFER_SIZE; + // Use assertions to check for errors. + bool assert = false; }; explicit Verifier(const uint8_t *const buf, const size_t buf_len, const Options &opts) : buf_(buf), size_(buf_len), opts_(opts) { - FLATBUFFERS_ASSERT(size_ < FLATBUFFERS_MAX_BUFFER_SIZE); + FLATBUFFERS_ASSERT(size_ < opts.max_size); } // Deprecated API, please construct with Verifier::Options. @@ -58,7 +62,7 @@ class Verifier FLATBUFFERS_FINAL_CLASS { bool Check(const bool ok) const { // clang-format off #ifdef FLATBUFFERS_DEBUG_VERIFICATION_FAILURE - FLATBUFFERS_ASSERT(ok); + if (opts_.assert) { FLATBUFFERS_ASSERT(ok); } #endif #ifdef FLATBUFFERS_TRACK_VERIFIER_BUFFER_SIZE if (!ok) @@ -113,41 +117,43 @@ class Verifier FLATBUFFERS_FINAL_CLASS { } // Verify a pointer (may be NULL) of any vector type. - template bool VerifyVector(const Vector *const vec) const { - return !vec || VerifyVectorOrString(reinterpret_cast(vec), - sizeof(T)); + template + bool VerifyVector(const Vector *const vec) const { + return !vec || VerifyVectorOrString( + reinterpret_cast(vec), sizeof(T)); } // Verify a pointer (may be NULL) of a vector to struct. - template - bool VerifyVector(const Vector *const vec) const { - return VerifyVector(reinterpret_cast *>(vec)); + template + bool VerifyVector(const Vector *const vec) const { + return VerifyVector(reinterpret_cast *>(vec)); } // Verify a pointer (may be NULL) to string. bool VerifyString(const String *const str) const { size_t end; - return !str || (VerifyVectorOrString(reinterpret_cast(str), - 1, &end) && + return !str || (VerifyVectorOrString( + reinterpret_cast(str), 1, &end) && Verify(end, 1) && // Must have terminator Check(buf_[end] == '\0')); // Terminating byte must be 0. } // Common code between vectors and strings. + template bool VerifyVectorOrString(const uint8_t *const vec, const size_t elem_size, size_t *const end = nullptr) const { - const auto veco = static_cast(vec - buf_); + const auto vec_offset = static_cast(vec - buf_); // Check we can read the size field. - if (!Verify(veco)) return false; + if (!Verify(vec_offset)) return false; // Check the whole array. If this is a string, the byte past the array must // be 0. - const auto size = ReadScalar(vec); - const auto max_elems = FLATBUFFERS_MAX_BUFFER_SIZE / elem_size; + const LenT size = ReadScalar(vec); + const auto max_elems = opts_.max_size / elem_size; if (!Check(size < max_elems)) return false; // Protect against byte_size overflowing. - const auto byte_size = sizeof(size) + elem_size * size; - if (end) *end = veco + byte_size; - return Verify(veco, byte_size); + const auto byte_size = sizeof(LenT) + elem_size * size; + if (end) *end = vec_offset + byte_size; + return Verify(vec_offset, byte_size); } // Special case for string contents, after the above has been called. @@ -171,8 +177,8 @@ class Verifier FLATBUFFERS_FINAL_CLASS { return true; } - __suppress_ubsan__("unsigned-integer-overflow") bool VerifyTableStart( - const uint8_t *const table) { + FLATBUFFERS_SUPPRESS_UBSAN("unsigned-integer-overflow") + bool VerifyTableStart(const uint8_t *const table) { // Check the vtable offset. const auto tableo = static_cast(table - buf_); if (!Verify(tableo)) return false; @@ -203,7 +209,7 @@ class Verifier FLATBUFFERS_FINAL_CLASS { } // Call T::Verify, which must be in the generated code for this type. - const auto o = VerifyOffset(start); + const auto o = VerifyOffset(start); return Check(o != 0) && reinterpret_cast(buf_ + start + o)->Verify(*this) // clang-format off @@ -214,8 +220,8 @@ class Verifier FLATBUFFERS_FINAL_CLASS { // clang-format on } - template - bool VerifyNestedFlatBuffer(const Vector *const buf, + template + bool VerifyNestedFlatBuffer(const Vector *const buf, const char *const identifier) { // Caller opted out of this. if (!opts_.check_nested_flatbuffers) return true; @@ -226,7 +232,7 @@ class Verifier FLATBUFFERS_FINAL_CLASS { // If there is a nested buffer, it must be greater than the min size. if (!Check(buf->size() >= FLATBUFFERS_MIN_BUFFER_SIZE)) return false; - Verifier nested_verifier(buf->data(), buf->size()); + Verifier nested_verifier(buf->data(), buf->size(), opts_); return nested_verifier.VerifyBuffer(identifier); } @@ -237,29 +243,32 @@ class Verifier FLATBUFFERS_FINAL_CLASS { return VerifyBufferFromStart(identifier, 0); } - template + template bool VerifySizePrefixedBuffer(const char *const identifier) { - return Verify(0U) && - Check(ReadScalar(buf_) == size_ - sizeof(uoffset_t)) && - VerifyBufferFromStart(identifier, sizeof(uoffset_t)); + return Verify(0U) && + // Ensure the prefixed size is within the bounds of the provided + // length. + Check(ReadScalar(buf_) + sizeof(SizeT) <= size_) && + VerifyBufferFromStart(identifier, sizeof(SizeT)); } - uoffset_t VerifyOffset(const size_t start) const { - if (!Verify(start)) return 0; - const auto o = ReadScalar(buf_ + start); + template + size_t VerifyOffset(const size_t start) const { + if (!Verify(start)) return 0; + const auto o = ReadScalar(buf_ + start); // May not point to itself. if (!Check(o != 0)) return 0; - // Can't wrap around / buffers are max 2GB. - if (!Check(static_cast(o) >= 0)) return 0; + // Can't wrap around larger than the max size. + if (!Check(static_cast(o) >= 0)) return 0; // Must be inside the buffer to create a pointer from it (pointer outside // buffer is UB). if (!Verify(start + o, 1)) return 0; return o; } - uoffset_t VerifyOffset(const uint8_t *const base, - const voffset_t start) const { - return VerifyOffset(static_cast(base - buf_) + start); + template + size_t VerifyOffset(const uint8_t *const base, const voffset_t start) const { + return VerifyOffset(static_cast(base - buf_) + start); } // Called at the start of a table to increase counters measuring data @@ -312,6 +321,12 @@ class Verifier FLATBUFFERS_FINAL_CLASS { std::vector *flex_reuse_tracker_ = nullptr; }; +// Specialization for 64-bit offsets. +template<> +inline size_t Verifier::VerifyOffset(const size_t start) const { + return VerifyOffset(start); +} + } // namespace flatbuffers #endif // FLATBUFFERS_VERIFIER_H_ -- cgit mrf-deployment