Change SizedPrefixed verifier to be <= provided size (#7957)

* Change SizedPrefixed verifier to be <= provided size

* add GetSizePrefixedBufferLength()
This commit is contained in:
Derek Bailey
2023-05-11 12:21:50 -07:00
committed by GitHub
parent 66e9d9823a
commit 33212657ae
3 changed files with 43 additions and 8 deletions

View File

@@ -81,6 +81,18 @@ inline SizeT GetPrefixedSize(const uint8_t *buf) {
return ReadScalar<SizeT>(buf);
}
// Gets the total length of the buffer given a sized prefixed FlatBuffer.
//
// This includes the size of the prefix as well as the buffer:
//
// [size prefix][flatbuffer]
// |---------length--------|
template<typename SizeT = uoffset_t>
inline SizeT GetSizePrefixedBufferLength(const uint8_t * const buf) {
return ReadScalar<SizeT>(buf) + sizeof(SizeT);
}
// Base class for native objects (FlatBuffer data de-serialized into native
// C++ data structures).
// Contains no functionality, purely documentative.