From e2be0c0b0605b38e11a8710a8bae38d7f86a7679 Mon Sep 17 00:00:00 2001 From: Derek Bailey Date: Wed, 23 Mar 2022 21:51:32 -0700 Subject: [PATCH] Handle root offset and root table vtable invalidation (#7177) * Handle invalid root offset * Handle vtable offset invalidation * Added script generator. Add more cases through vtable ref table size * review responses * vtable offset validation * Moved padding insertion to the end. Tests invalid field lenghts * table offsets validated. Added type after field * validate string length * add todo * invalid vector length * invalid structs * general cleanup * reworded invalid offsets * example for vector of structs * invalid vector of tables * invalid vector of strings * invalid vector of scalars * vector of unions * validate union type value * invalid vector union type values --- reflection/reflection.fbs | 1 + src/annotated_binary_text_gen.cpp | 1 + src/binary_annotator.cpp | 1059 ++++++++++++----- src/binary_annotator.h | 92 +- src/flatc.cpp | 4 +- tests/annotated_binary/annotated_binary.afb | 44 +- .../annotated_binary/generate_annotations.py | 76 ++ tests/annotated_binary/tests/README.md | 125 ++ .../tests/invalid_root_offset.afb | 93 ++ .../tests/invalid_root_offset.bin | Bin 0 -> 672 bytes .../tests/invalid_root_table_too_short.afb | 21 + .../tests/invalid_root_table_too_short.bin | Bin 0 -> 70 bytes .../invalid_root_table_vtable_offset.afb | 98 ++ .../invalid_root_table_vtable_offset.bin | Bin 0 -> 672 bytes .../tests/invalid_string_length.afb | 295 +++++ .../tests/invalid_string_length.bin | Bin 0 -> 672 bytes .../tests/invalid_string_length_cut_short.afb | 80 ++ .../tests/invalid_string_length_cut_short.bin | Bin 0 -> 174 bytes .../invalid_struct_array_field_cut_short.afb | 72 ++ .../invalid_struct_array_field_cut_short.bin | Bin 0 -> 106 bytes .../tests/invalid_struct_field_cut_short.afb | 69 ++ .../tests/invalid_struct_field_cut_short.bin | Bin 0 -> 94 bytes .../tests/invalid_table_field_offset.afb | 77 ++ .../tests/invalid_table_field_offset.bin | Bin 0 -> 150 bytes .../tests/invalid_table_field_size.afb | 68 ++ .../tests/invalid_table_field_size.bin | Bin 0 -> 82 bytes .../tests/invalid_union_type_value.afb | 293 +++++ .../tests/invalid_union_type_value.bin | Bin 0 -> 672 bytes .../tests/invalid_vector_length_cut_short.afb | 140 +++ .../tests/invalid_vector_length_cut_short.bin | Bin 0 -> 310 bytes .../invalid_vector_scalars_cut_short.afb | 191 +++ .../invalid_vector_scalars_cut_short.bin | Bin 0 -> 449 bytes .../invalid_vector_strings_cut_short.afb | 154 +++ .../invalid_vector_strings_cut_short.bin | Bin 0 -> 374 bytes .../invalid_vector_structs_cut_short.afb | 144 +++ .../invalid_vector_structs_cut_short.bin | Bin 0 -> 340 bytes .../tests/invalid_vector_tables_cut_short.afb | 209 ++++ .../tests/invalid_vector_tables_cut_short.bin | Bin 0 -> 478 bytes .../tests/invalid_vector_union_type_value.afb | 293 +++++ .../tests/invalid_vector_union_type_value.bin | Bin 0 -> 672 bytes .../tests/invalid_vector_unions_cut_short.afb | 209 ++++ .../tests/invalid_vector_unions_cut_short.bin | Bin 0 -> 478 bytes .../tests/invalid_vtable_field_offset.afb | 286 +++++ .../tests/invalid_vtable_field_offset.bin | Bin 0 -> 672 bytes .../tests/invalid_vtable_ref_table_size.afb | 360 ++++++ .../tests/invalid_vtable_ref_table_size.bin | Bin 0 -> 672 bytes .../invalid_vtable_ref_table_size_short.afb | 297 +++++ .../invalid_vtable_ref_table_size_short.bin | Bin 0 -> 672 bytes .../tests/invalid_vtable_size.afb | 99 ++ .../tests/invalid_vtable_size.bin | Bin 0 -> 672 bytes .../tests/invalid_vtable_size_short.afb | 99 ++ .../tests/invalid_vtable_size_short.bin | Bin 0 -> 672 bytes 52 files changed, 4712 insertions(+), 337 deletions(-) create mode 100755 tests/annotated_binary/generate_annotations.py create mode 100644 tests/annotated_binary/tests/README.md create mode 100644 tests/annotated_binary/tests/invalid_root_offset.afb create mode 100644 tests/annotated_binary/tests/invalid_root_offset.bin create mode 100644 tests/annotated_binary/tests/invalid_root_table_too_short.afb create mode 100644 tests/annotated_binary/tests/invalid_root_table_too_short.bin create mode 100644 tests/annotated_binary/tests/invalid_root_table_vtable_offset.afb create mode 100644 tests/annotated_binary/tests/invalid_root_table_vtable_offset.bin create mode 100644 tests/annotated_binary/tests/invalid_string_length.afb create mode 100644 tests/annotated_binary/tests/invalid_string_length.bin create mode 100644 tests/annotated_binary/tests/invalid_string_length_cut_short.afb create mode 100644 tests/annotated_binary/tests/invalid_string_length_cut_short.bin create mode 100644 tests/annotated_binary/tests/invalid_struct_array_field_cut_short.afb create mode 100644 tests/annotated_binary/tests/invalid_struct_array_field_cut_short.bin create mode 100644 tests/annotated_binary/tests/invalid_struct_field_cut_short.afb create mode 100644 tests/annotated_binary/tests/invalid_struct_field_cut_short.bin create mode 100644 tests/annotated_binary/tests/invalid_table_field_offset.afb create mode 100644 tests/annotated_binary/tests/invalid_table_field_offset.bin create mode 100644 tests/annotated_binary/tests/invalid_table_field_size.afb create mode 100644 tests/annotated_binary/tests/invalid_table_field_size.bin create mode 100644 tests/annotated_binary/tests/invalid_union_type_value.afb create mode 100644 tests/annotated_binary/tests/invalid_union_type_value.bin create mode 100644 tests/annotated_binary/tests/invalid_vector_length_cut_short.afb create mode 100644 tests/annotated_binary/tests/invalid_vector_length_cut_short.bin create mode 100644 tests/annotated_binary/tests/invalid_vector_scalars_cut_short.afb create mode 100644 tests/annotated_binary/tests/invalid_vector_scalars_cut_short.bin create mode 100644 tests/annotated_binary/tests/invalid_vector_strings_cut_short.afb create mode 100644 tests/annotated_binary/tests/invalid_vector_strings_cut_short.bin create mode 100644 tests/annotated_binary/tests/invalid_vector_structs_cut_short.afb create mode 100644 tests/annotated_binary/tests/invalid_vector_structs_cut_short.bin create mode 100644 tests/annotated_binary/tests/invalid_vector_tables_cut_short.afb create mode 100644 tests/annotated_binary/tests/invalid_vector_tables_cut_short.bin create mode 100644 tests/annotated_binary/tests/invalid_vector_union_type_value.afb create mode 100644 tests/annotated_binary/tests/invalid_vector_union_type_value.bin create mode 100644 tests/annotated_binary/tests/invalid_vector_unions_cut_short.afb create mode 100644 tests/annotated_binary/tests/invalid_vector_unions_cut_short.bin create mode 100644 tests/annotated_binary/tests/invalid_vtable_field_offset.afb create mode 100644 tests/annotated_binary/tests/invalid_vtable_field_offset.bin create mode 100644 tests/annotated_binary/tests/invalid_vtable_ref_table_size.afb create mode 100644 tests/annotated_binary/tests/invalid_vtable_ref_table_size.bin create mode 100644 tests/annotated_binary/tests/invalid_vtable_ref_table_size_short.afb create mode 100644 tests/annotated_binary/tests/invalid_vtable_ref_table_size_short.bin create mode 100644 tests/annotated_binary/tests/invalid_vtable_size.afb create mode 100644 tests/annotated_binary/tests/invalid_vtable_size.bin create mode 100644 tests/annotated_binary/tests/invalid_vtable_size_short.afb create mode 100644 tests/annotated_binary/tests/invalid_vtable_size_short.bin diff --git a/reflection/reflection.fbs b/reflection/reflection.fbs index c3665ebdc..6dfeff66a 100644 --- a/reflection/reflection.fbs +++ b/reflection/reflection.fbs @@ -37,6 +37,7 @@ table Type { index:int = -1; // If base_type == Object, index into "objects" below. // If base_type == Union, UnionType, or integral derived // from an enum, index into "enums" below. + // If base_type == Vector && element == Union or UnionType. fixed_length:uint16 = 0; // Only if base_type == Array. /// The size (octets) of the `base_type` field. base_size:uint = 4; // 4 Is a common size due to offsets being that size. diff --git a/src/annotated_binary_text_gen.cpp b/src/annotated_binary_text_gen.cpp index 6f1fa6a74..817009451 100644 --- a/src/annotated_binary_text_gen.cpp +++ b/src/annotated_binary_text_gen.cpp @@ -96,6 +96,7 @@ static std::string ToValueString(const BinaryRegion ®ion, return ToValueString(region, binary); case BinaryRegionType::Double: return ToValueString(region, binary); case BinaryRegionType::Float: return ToValueString(region, binary); + case BinaryRegionType::UType: return ToValueString(region, binary); // Handle Offsets separately, incase they add additional details. case BinaryRegionType::UOffset: diff --git a/src/binary_annotator.cpp b/src/binary_annotator.cpp index 862936c34..b885e41db 100644 --- a/src/binary_annotator.cpp +++ b/src/binary_annotator.cpp @@ -1,6 +1,6 @@ #include "binary_annotator.h" -#include +#include #include #include "flatbuffers/reflection.h" @@ -9,6 +9,10 @@ namespace flatbuffers { namespace { +static bool BinaryRegionSort(const BinaryRegion &a, const BinaryRegion &b) { + return a.offset < b.offset; +} + static BinaryRegion MakeBinaryRegion( const uint64_t offset = 0, const uint64_t length = 0, const BinaryRegionType type = BinaryRegionType::Unknown, @@ -34,72 +38,68 @@ static BinarySection MakeBinarySection( return section; } -static uint64_t BuildField(const uint64_t offset, - const reflection::Field *field, - std::vector ®ions) { - const uint64_t type_size = GetTypeSize(field->type()->base_type()); - const BinaryRegionType type = GetRegionType(field->type()->base_type()); - regions.emplace_back(MakeBinaryRegion( - offset, type_size, type, 0, 0, - std::string("table field `") + field->name()->c_str() + "` (" + - reflection::EnumNameBaseType(field->type()->base_type()) + ")")); - return offset + type_size; +static BinarySection MakeSingleRegionBinarySection(const std::string &name, + const BinarySectionType type, + const BinaryRegion ®ion) { + std::vector regions; + regions.push_back(region); + return MakeBinarySection(name, type, regions); } -static uint64_t BuildStructureField(const uint64_t offset, - const reflection::Object *object, - const reflection::Field *field, - std::vector ®ions) { - const uint64_t type_size = GetTypeSize(field->type()->base_type()); - regions.emplace_back(MakeBinaryRegion( - offset, type_size, GetRegionType(field->type()->base_type()), 0, 0, - std::string("struct field `") + object->name()->c_str() + "." + - field->name()->c_str() + "` (" + - reflection::EnumNameBaseType(field->type()->base_type()) + ")")); - return offset + type_size; -} - -static uint64_t BuildArrayField(uint64_t offset, - const reflection::Object *object, - const reflection::Field *field, - const uint16_t array_length, - std::vector ®ions) { - const uint64_t type_size = GetTypeSize(field->type()->element()); - for (uint16_t i = 0; i < array_length; ++i) { - regions.emplace_back(MakeBinaryRegion( - offset, type_size, GetRegionType(field->type()->element()), 0, 0, - std::string("array field `") + object->name()->c_str() + "." + - field->name()->c_str() + "[" + std::to_string(i) + "]` (" + - reflection::EnumNameBaseType(field->type()->element()) + ")")); - offset += type_size; - } - - // The following groups the complete array together which shows up nicely as - // an array, but then we don't show the individual values. So the above method - // treats each field of the array as a separate region. - // regions.emplace_back( - // BinaryRegion{ offset, array_length * type_size, - // GetRegionType(field->type()->element()), array_length, 0, - // std::string("array field '") + object->name()->c_str() + - // "." + field->name()->c_str() + "' value" }); - - return offset; -} - -static bool IsNonZeroRegion(uint64_t offset, uint64_t length, - const uint8_t *binary) { +static bool IsNonZeroRegion(const uint64_t offset, const uint64_t length, + const uint8_t *const binary) { for (uint64_t i = offset; i < offset + length; ++i) { if (binary[i] != 0) { return true; } } return false; } +static BinarySection GenerateMissingSection(const uint64_t offset, + const uint64_t length, + const uint8_t *const binary) { + std::vector regions; + + // Check if the region is all zeros or not, as that can tell us if it is + // padding or not. + if (IsNonZeroRegion(offset, length, binary)) { + // Some of the padding bytes are non-zero, so this might be an unknown + // section of the binary. + // TODO(dbaileychess): We could be a bit smarter with different sized + // alignments. For now, the 8 byte check encompasses all the smaller + // alignments. + regions.push_back(MakeBinaryRegion( + offset, length * sizeof(uint8_t), BinaryRegionType::Unknown, length, 0, + length < 8 ? "could be a corrupted padding region (non zero) " + "due to the length < 8 bytes." + : "WARN: nothing refers to this section.")); + + return MakeBinarySection("no known references", BinarySectionType::Unknown, + std::move(regions)); + } + + // This region is most likely padding. + regions.push_back(MakeBinaryRegion( + offset, length * sizeof(uint8_t), BinaryRegionType::Uint8, length, 0, + // Output a different annotation if the pad bytes exceed what we + // expect to be the maximum padding. + length > 7 ? "likely padding but might be an unknown section " + "due to being larger than 7 bytes" + : "padding")); + + return MakeBinarySection("", BinarySectionType::Padding, std::move(regions)); +} + } // namespace std::map BinaryAnnotator::Annotate() { flatbuffers::Verifier verifier(bfbs_, static_cast(bfbs_length_)); if (!reflection::VerifySchemaBuffer(verifier)) { return {}; } + // The binary is too short to read as a flatbuffers. + // TODO(dbaileychess): We could spit out the annotated buffer sections, but + // I'm not sure if it is worth it. + if (binary_length_ < 4) { return {}; } + // Make sure we start with a clean slate. vtables_.clear(); strings_.clear(); @@ -109,62 +109,158 @@ std::map BinaryAnnotator::Annotate() { // The returned offset will point to the root_table location. const uint64_t root_table_offset = BuildHeader(0); - // Build the root table, and all else will be referenced from it. - BuildTable(root_table_offset, BinarySectionType::RootTable, - schema_->root_table()); + if (IsValidOffset(root_table_offset)) { + // Build the root table, and all else will be referenced from it. + BuildTable(root_table_offset, BinarySectionType::RootTable, + schema_->root_table()); + } - // Now that all the sections are built, scan the regions between them and - // insert padding bytes that are implied. + // Now that all the sections are built, make sure the binary sections are + // contiguous. + FixMissingRegions(); + + // Then scan the area between BinarySections insert padding sections that are + // implied. FixMissingSections(); return sections_; } -uint64_t BinaryAnnotator::BuildHeader(const uint64_t offset) { +uint64_t BinaryAnnotator::BuildHeader(const uint64_t header_offset) { + const auto root_table_offset = ReadScalar(header_offset); + + if (!root_table_offset.has_value()) { + // This shouldn't occur, since we validate the min size of the buffer + // before. But for completion sake, we shouldn't read passed the binary end. + return std::numeric_limits::max(); + } + std::vector regions; - + uint64_t offset = header_offset; // TODO(dbaileychess): sized prefixed value - const uint32_t root_table_offset = GetScalar(offset); - regions.emplace_back(MakeBinaryRegion( - offset, sizeof(uint32_t), BinaryRegionType::UOffset, 0, root_table_offset, - std::string("offset to root table `") + - schema_->root_table()->name()->str() + "`")); - if (IsNonZeroRegion(offset, 4, binary_)) { - // Check if the file identifier region has non-zero data, and assume its the - // file identifier. Otherwise, it will get filled in with padding later. - regions.emplace_back(MakeBinaryRegion( - offset + sizeof(uint32_t), 4 * sizeof(uint8_t), BinaryRegionType::Char, - 4, 0, std::string("File Identifier"))); + const std::string name = std::string("offset to root table `") + + schema_->root_table()->name()->str() + "`"; + + if (IsValidOffset(root_table_offset.value())) { + regions.push_back(MakeBinaryRegion(offset, sizeof(uint32_t), + BinaryRegionType::UOffset, 0, + root_table_offset.value(), name)); + } else { + regions.push_back(MakeBinaryRegion( + offset, sizeof(uint32_t), BinaryRegionType::UOffset, 0, + root_table_offset.value(), + "ERROR: " + name + ". Invalid offset, points to outside the binary.")); + } + offset += sizeof(uint32_t); + + if (IsValidRead(offset, flatbuffers::kFileIdentifierLength) && + IsNonZeroRegion(offset, flatbuffers::kFileIdentifierLength, binary_)) { + // Check if the file identifier region has non-zero data, and assume its + // the file identifier. Otherwise, it will get filled in with padding + // later. + regions.push_back(MakeBinaryRegion( + offset, flatbuffers::kFileIdentifierLength * sizeof(uint8_t), + BinaryRegionType::Char, flatbuffers::kFileIdentifierLength, 0, + std::string("File Identifier"))); } sections_.insert(std::make_pair( - offset, MakeBinarySection("", BinarySectionType::Header, regions))); - return root_table_offset; + header_offset, + MakeBinarySection("", BinarySectionType::Header, regions))); + + return root_table_offset.value(); } -void BinaryAnnotator::BuildVTable(uint64_t offset, - const reflection::Object *table) { - const uint64_t vtable_offset = offset; - +void BinaryAnnotator::BuildVTable(const uint64_t vtable_offset, + const reflection::Object *const table, + const uint64_t offset_of_referring_table) { // First see if we have used this vtable before, if so skip building it again. auto it = vtables_.find(vtable_offset); if (it != vtables_.end()) { return; } - std::vector regions; + const auto vtable_length = ReadScalar(vtable_offset); + if (!vtable_length.has_value()) { + const uint64_t remaining = RemainingBytes(vtable_offset); + + AddSection(vtable_offset, + MakeSingleRegionBinarySection( + table->name()->str(), BinarySectionType::VTable, + MakeBinaryRegion(vtable_offset, remaining, + BinaryRegionType::Unknown, remaining, 0, + "ERROR: size of this vtable. Incomplete " + "binary, expected to read 2 bytes here"))); + return; + } // Vtables start with the size of the vtable - const uint16_t vtable_size = GetScalar(offset); - regions.emplace_back(MakeBinaryRegion(offset, sizeof(uint16_t), - BinaryRegionType::Uint16, 0, 0, - std::string("size of this vtable"))); - offset += sizeof(uint16_t); + const uint16_t vtable_size = vtable_length.value(); + + if (!IsValidOffset(vtable_offset + vtable_size - 1)) { + // The vtable_size points to off the end of the binary. + AddSection( + vtable_offset, + MakeSingleRegionBinarySection( + table->name()->str(), BinarySectionType::VTable, + MakeBinaryRegion( + vtable_offset, sizeof(uint16_t), BinaryRegionType::Uint16, 0, 0, + "ERROR: size of this vtable. Longer than the binary"))); + + return; + } else if (vtable_size < 2 * sizeof(uint16_t)) { + // The size includes itself and the table size which are both uint16_t. + AddSection(vtable_offset, + MakeSingleRegionBinarySection( + table->name()->str(), BinarySectionType::VTable, + MakeBinaryRegion(vtable_offset, sizeof(uint16_t), + BinaryRegionType::Uint16, 0, 0, + "ERROR: size of this vtable. Shorter than " + "the minimum 4 bytes"))); + return; + } + + std::vector regions; + + regions.push_back(MakeBinaryRegion(vtable_offset, sizeof(uint16_t), + BinaryRegionType::Uint16, 0, 0, + std::string("size of this vtable"))); + uint64_t offset = vtable_offset + sizeof(uint16_t); + + // Ensure we can read the next uint16_t field, which is the size of the + // referring table. + const auto table_length = ReadScalar(offset); + + if (!table_length.has_value()) { + const uint64_t remaining = RemainingBytes(offset); + + AddSection(offset, + MakeSingleRegionBinarySection( + table->name()->str(), BinarySectionType::VTable, + MakeBinaryRegion(offset, remaining, + BinaryRegionType::Unknown, remaining, 0, + "ERROR: sizeof referring table. Incomplete " + "binary, expected to read 2 bytes here"))); + return; + } // Then they have the size of the table they reference. - const uint16_t table_size = GetScalar(offset); - regions.emplace_back( - MakeBinaryRegion(offset, sizeof(uint16_t), BinaryRegionType::Uint16, 0, 0, - std::string("size of referring table"))); + const uint16_t table_size = table_length.value(); + + if (!IsValidOffset(offset_of_referring_table + table_size - 1)) { + regions.push_back(MakeBinaryRegion( + offset, sizeof(uint16_t), BinaryRegionType::Uint16, 0, 0, + std::string("ERROR: size of referring table. Size of table is larger " + "than the binary."))); + } else if (table_size < 4) { + regions.push_back(MakeBinaryRegion( + offset, sizeof(uint16_t), BinaryRegionType::Uint16, 0, 0, + std::string("ERROR: size of referring table. Size of table is " + "smaller than the minimum 4 bytes"))); + } else { + regions.push_back(MakeBinaryRegion(offset, sizeof(uint16_t), + BinaryRegionType::Uint16, 0, 0, + std::string("size of referring table"))); + } offset += sizeof(uint16_t); const uint64_t offset_start = offset; @@ -193,15 +289,39 @@ void BinaryAnnotator::BuildVTable(uint64_t offset, return; } - const uint16_t offset_from_table = GetScalar(field_offset); + const std::string field_comment = + std::string("offset to field `") + field->name()->c_str() + + "` (id: " + std::to_string(field->id()) + ")"; + + const auto offset_from_table = ReadScalar(field_offset); + + if (!offset_from_table.has_value()) { + const uint64_t remaining = RemainingBytes(field_offset); + + regions.push_back(MakeBinaryRegion( + field_offset, remaining, BinaryRegionType::Unknown, remaining, 0, + "ERROR: " + field_comment + + ". Incomplete binary, expected to read 2 bytes here")); + + return; + } + + if (!IsValidOffset(offset_of_referring_table + offset_from_table.value() - + 1)) { + regions.push_back(MakeBinaryRegion( + field_offset, sizeof(uint16_t), BinaryRegionType::VOffset, 0, 0, + "ERROR: " + field_comment + + ". Invalid offset, points to outside the binary.")); + return; + } VTable::Entry entry; entry.field = field; - entry.offset_from_table = offset_from_table; + entry.offset_from_table = offset_from_table.value(); fields.insert(std::make_pair(field->id(), entry)); std::string default_label; - if (offset_from_table == 0) { + if (offset_from_table.value() == 0) { // Not present, so could be default or be optional. if (field->required()) { // If this is a required field, make it known this is an error. @@ -228,10 +348,9 @@ void BinaryAnnotator::BuildVTable(uint64_t offset, } } - regions.push_back(MakeBinaryRegion( - field_offset, sizeof(uint16_t), BinaryRegionType::VOffset, 0, 0, - std::string("offset to field `") + field->name()->c_str() + - "` (id: " + std::to_string(field->id()) + ")" + default_label)); + regions.push_back(MakeBinaryRegion(field_offset, sizeof(uint16_t), + BinaryRegionType::VOffset, 0, 0, + field_comment + default_label)); fields_processed++; }); @@ -243,11 +362,22 @@ void BinaryAnnotator::BuildVTable(uint64_t offset, for (uint16_t id = fields_processed; id < expectant_vtable_fields; ++id) { const uint64_t field_offset = offset_start + id * sizeof(uint16_t); - const uint16_t offset_from_table = GetScalar(field_offset); + + const auto offset_from_table = ReadScalar(field_offset); + + if (!offset_from_table.has_value()) { + const uint64_t remaining = RemainingBytes(field_offset); + + regions.push_back(MakeBinaryRegion( + field_offset, remaining, BinaryRegionType::Unknown, remaining, 0, + "ERROR: offset to unknown field (id: " + std::to_string(id) + + "). Incomplete binary, expected to read 2 bytes here")); + continue; + } VTable::Entry entry; entry.field = nullptr; // No field to reference. - entry.offset_from_table = offset_from_table; + entry.offset_from_table = offset_from_table.value(); fields.insert(std::make_pair(id, entry)); regions.push_back(MakeBinaryRegion( @@ -267,29 +397,71 @@ void BinaryAnnotator::BuildVTable(uint64_t offset, vtables_[vtable_offset] = vtable; } -void BinaryAnnotator::BuildTable(uint64_t offset, const BinarySectionType type, - const reflection::Object *table) { - std::vector regions; - const uint64_t table_offset = offset; +void BinaryAnnotator::BuildTable(const uint64_t table_offset, + const BinarySectionType type, + const reflection::Object *const table) { + const auto vtable_soffset = ReadScalar(table_offset); + + if (!vtable_soffset.has_value()) { + const uint64_t remaining = RemainingBytes(table_offset); + + AddSection(table_offset, + MakeSingleRegionBinarySection( + table->name()->str(), type, + MakeBinaryRegion(table_offset, remaining, + BinaryRegionType::Unknown, remaining, 0, + "ERROR: offset to vtable. Incomplete " + "binary, expected to read 4 bytes here"))); + + // If there aren't enough bytes left to read the vtable offset, there is + // nothing we can do. + return; + } // Tables start with the vtable - const uint64_t vtable_offset = table_offset - GetScalar(offset); - regions.emplace_back( - MakeBinaryRegion(offset, sizeof(int32_t), BinaryRegionType::SOffset, 0, - vtable_offset, std::string("offset to vtable"))); - offset += sizeof(int32_t); + const uint64_t vtable_offset = table_offset - vtable_soffset.value(); + + if (!IsValidOffset(vtable_offset)) { + AddSection(table_offset, + MakeSingleRegionBinarySection( + table->name()->str(), type, + MakeBinaryRegion(table_offset, sizeof(int32_t), + BinaryRegionType::SOffset, 0, vtable_offset, + "ERROR: offset to vtable. Invalid offset, " + "points to outside the binary."))); + + // There isn't much to do with an invalid vtable offset, as we won't be able + // to intepret the rest of the table fields. + return; + } + + std::vector regions; + regions.push_back( + MakeBinaryRegion(table_offset, sizeof(int32_t), BinaryRegionType::SOffset, + 0, vtable_offset, std::string("offset to vtable"))); // Parse the vtable first so we know what the rest of the fields in the table // are. - BuildVTable(vtable_offset, table); + BuildVTable(vtable_offset, table, table_offset); - const VTable &vtable = vtables_.at(vtable_offset); + auto vtable_entry = vtables_.find(vtable_offset); + if (vtable_entry == vtables_.end()) { + // There is no valid vtable for this table, so we cannot process the rest of + // the table entries. + return; + } + + const VTable &vtable = vtable_entry->second; // This is the size and length of this table. const uint16_t table_size = vtable.table_size; - const uint64_t table_end_offset = table_offset + table_size; + uint64_t table_end_offset = table_offset + table_size; - const uint64_t field_offset_start = offset; + if (!IsValidOffset(table_end_offset - 1)) { + // We already validated the table size in BuildVTable, but we have to make + // sure we don't use a bad value here. + table_end_offset = binary_length_; + } // We need to iterate over the vtable fields by their offset in the binary, // not by their IDs. So copy them over to another vector that we can sort on @@ -317,6 +489,11 @@ void BinaryAnnotator::BuildTable(uint64_t offset, const BinarySectionType type, // The field offsets are relative to the start of the table. const uint64_t field_offset = table_offset + offset_from_table; + if (!IsValidOffset(field_offset)) { + // The field offset is larger than the binary, nothing we can do. + continue; + } + // We have a vtable entry for a non-existant field, that means its a binary // generated by a newer schema than we are currently processing. if (field == nullptr) { @@ -330,26 +507,100 @@ void BinaryAnnotator::BuildTable(uint64_t offset, const BinarySectionType type, field_offset; std::string hint; + if (unknown_field_length == 4) { - // The field is 4 in length, so it could be an offset? Provide a hint. - hint += " (field_offset)); - hint += ">"; + const auto relative_offset = ReadScalar(field_offset); + if (relative_offset.has_value()) { + // The field is 4 in length, so it could be an offset? Provide a hint. + hint += " type()->base_type())) { // These are the raw values store in the table. - offset = BuildField(field_offset, field, regions); + const uint64_t type_size = GetTypeSize(field->type()->base_type()); + const BinaryRegionType region_type = + GetRegionType(field->type()->base_type()); + + const std::string name = + "table field `" + std::string(field->name()->c_str()) + "` (" + + reflection::EnumNameBaseType(field->type()->base_type()) + ")"; + + if (!IsValidRead(field_offset, type_size)) { + const uint64_t remaining = RemainingBytes(field_offset); + + regions.push_back(MakeBinaryRegion( + field_offset, remaining, BinaryRegionType::Unknown, remaining, 0, + "ERROR: " + name + ". Expected " + std::to_string(type_size) + + " bytes.")); + continue; + } + + if (IsUnionType(field)) { + // This is a type for a union. Validate the value + const auto enum_value = ReadScalar(field_offset); + + // This should alawys have a value, due to the IsValidRead check above. + if (!IsValidUnionValue(field, enum_value.value())) { + regions.push_back(MakeBinaryRegion( + field_offset, type_size, region_type, 0, 0, + "ERROR: " + name + " . Invalid union type value.")); + continue; + } + } + + regions.push_back( + MakeBinaryRegion(field_offset, type_size, region_type, 0, 0, name)); continue; } + // Read the offset + const auto offset_from_field = ReadScalar(field_offset); + uint64_t offset_of_next_item = 0; + const std::string offset_prefix = + "offset to field `" + std::string(field->name()->c_str()) + "`"; + + // Validate any field that isn't inline (i.e., non-structs). + if (!IsInlineField(field)) { + if (!offset_from_field.has_value()) { + const uint64_t remaining = RemainingBytes(field_offset); + regions.push_back(MakeBinaryRegion( + field_offset, remaining, BinaryRegionType::Unknown, remaining, 0, + std::string("ERROR: ") + offset_prefix + + ". Incomplete binary, expected to read 4 bytes here")); + continue; + } + + offset_of_next_item = field_offset + offset_from_field.value(); + + if (!IsValidOffset(offset_of_next_item)) { + regions.push_back( + MakeBinaryRegion(field_offset, sizeof(uint32_t), + BinaryRegionType::UOffset, 0, offset_of_next_item, + std::string("ERROR: ") + offset_prefix + + ". Location is outside the binary.")); + continue; + } + } + switch (field->type()->base_type()) { case reflection::BaseType::Obj: { const reflection::Object *next_object = @@ -357,70 +608,70 @@ void BinaryAnnotator::BuildTable(uint64_t offset, const BinarySectionType type, if (next_object->is_struct()) { // Structs are stored inline. - offset = BuildStruct(field_offset, regions, next_object); + BuildStruct(field_offset, regions, next_object); } else { - const uint64_t next_object_offset = - field_offset + GetScalar(field_offset); - regions.emplace_back(MakeBinaryRegion( + regions.push_back(MakeBinaryRegion( field_offset, sizeof(uint32_t), BinaryRegionType::UOffset, 0, - next_object_offset, - std::string("offset to field `") + field->name()->c_str() + "`")); - offset += sizeof(uint32_t); + offset_of_next_item, offset_prefix + " (table)")); - BuildTable(next_object_offset, BinarySectionType::Table, next_object); + BuildTable(offset_of_next_item, BinarySectionType::Table, + next_object); } } break; case reflection::BaseType::String: { - const uint64_t string_offset = - field_offset + GetScalar(field_offset); - - regions.emplace_back(MakeBinaryRegion( + regions.push_back(MakeBinaryRegion( field_offset, sizeof(uint32_t), BinaryRegionType::UOffset, 0, - string_offset, - std::string("offset to field `") + field->name()->c_str() + "`")); - - BuildString(string_offset, table, field); + offset_of_next_item, offset_prefix + " (string)")); + BuildString(offset_of_next_item, table, field); } break; case reflection::BaseType::Vector: { - const uint64_t vector_offset = - field_offset + GetScalar(field_offset); - - regions.emplace_back(MakeBinaryRegion( + regions.push_back(MakeBinaryRegion( field_offset, sizeof(uint32_t), BinaryRegionType::UOffset, 0, - vector_offset, - std::string("offset to field `") + field->name()->c_str() + "`")); - - BuildVector(vector_offset, table, field, table_offset, vtable); + offset_of_next_item, offset_prefix + " (vector)")); + BuildVector(offset_of_next_item, table, field, table_offset, vtable); } break; case reflection::BaseType::Union: { - const uint64_t union_offset = - field_offset + GetScalar(field_offset); + const uint64_t union_offset = offset_of_next_item; // The union type field is always one less than the union itself. const uint16_t union_type_id = field->id() - 1; - auto vtable_entry = vtable.fields.find(union_type_id); - if (vtable_entry == vtable.fields.end()) { + auto vtable_field = vtable.fields.find(union_type_id); + if (vtable_field == vtable.fields.end()) { // TODO(dbaileychess): need to capture this error condition. break; } const uint64_t type_offset = - table_offset + vtable_entry->second.offset_from_table; + table_offset + vtable_field->second.offset_from_table; - const uint8_t realized_type = GetScalar(type_offset); + const auto realized_type = ReadScalar(type_offset); + if (!realized_type.has_value()) { + const uint64_t remaining = RemainingBytes(type_offset); + regions.push_back(MakeBinaryRegion( + type_offset, remaining, BinaryRegionType::Unknown, remaining, 0, + "ERROR: " + offset_prefix + + " (union). Incomplete binary, expected to read 1 byte here")); + continue; + } + + if (!IsValidUnionValue(field, realized_type.value())) { + // We already export an error in the union type field, so just skip + // building the union itself and it will default to an unreference + // Binary section. + continue; + } const std::string enum_type = - BuildUnion(union_offset, realized_type, field); + BuildUnion(union_offset, realized_type.value(), field); - regions.emplace_back(MakeBinaryRegion( + regions.push_back(MakeBinaryRegion( field_offset, sizeof(uint32_t), BinaryRegionType::UOffset, 0, union_offset, - std::string("offset to field `") + field->name()->c_str() + - "` (union of type `" + enum_type + "`)")); + offset_prefix + " (union of type `" + enum_type + "`)")); } break; @@ -428,74 +679,98 @@ void BinaryAnnotator::BuildTable(uint64_t offset, const BinarySectionType type, } } - // Fill in any regions that weren't covered above, as those are padding - // regions. - size_t region_index = 1; - std::vector padding_regions; - uint64_t i = field_offset_start; - while (region_index < regions.size() && i < table_end_offset) { - const uint64_t region_start = regions[region_index].offset; - const uint64_t region_end = region_start + regions[region_index].length; - - if (i < region_start) { - const uint64_t pad_bytes = region_start - i; - // We are at an index that is lower than any region, so pad upto its - // offset. - padding_regions.emplace_back( - MakeBinaryRegion(i, pad_bytes * sizeof(uint8_t), - BinaryRegionType::Uint8, pad_bytes, 0, "padding")); - i = region_end; - region_index++; - } else if (i < region_end) { - i = region_end + 1; - } else { - region_index++; - } - } - // Handle the case where there is padding after the last known binary // region. Calculate where we left off towards the expected end of the // table. + const uint64_t i = regions.back().offset + regions.back().length + 1; + if (i < table_end_offset) { const uint64_t pad_bytes = table_end_offset - i + 1; - padding_regions.emplace_back( - MakeBinaryRegion(i - 1, pad_bytes * sizeof(uint8_t), - BinaryRegionType::Uint8, pad_bytes, 0, "padding")); + regions.push_back(MakeBinaryRegion(i - 1, pad_bytes * sizeof(uint8_t), + BinaryRegionType::Uint8, pad_bytes, 0, + "padding")); } - regions.insert(regions.end(), padding_regions.begin(), padding_regions.end()); - - std::stable_sort(regions.begin(), regions.end(), - [&](const BinaryRegion &a, const BinaryRegion &b) { - return a.offset < b.offset; - }); - - sections_.insert(std::make_pair( - table_offset, - MakeBinarySection(table->name()->str(), type, std::move(regions)))); + AddSection(table_offset, + MakeBinarySection(table->name()->str(), type, std::move(regions))); } -uint64_t BinaryAnnotator::BuildStruct(uint64_t offset, +uint64_t BinaryAnnotator::BuildStruct(const uint64_t struct_offset, std::vector ®ions, - const reflection::Object *object) { - if (!object->is_struct()) { return offset; } + const reflection::Object *const object) { + if (!object->is_struct()) { return struct_offset; } + + uint64_t offset = struct_offset; // Loop over all the fields in increasing order ForAllFields(object, /*reverse=*/false, [&](const reflection::Field *field) { if (IsScalar(field->type()->base_type())) { - offset = BuildStructureField(offset, object, field, regions); + // Structure Field value + const uint64_t type_size = GetTypeSize(field->type()->base_type()); + const BinaryRegionType region_type = + GetRegionType(field->type()->base_type()); + const std::string name = + std::string("struct field `") + object->name()->c_str() + "." + + field->name()->c_str() + "` (" + + reflection::EnumNameBaseType(field->type()->base_type()) + ")"; + + if (!IsValidRead(offset, type_size)) { + const uint64_t remaining = RemainingBytes(offset); + regions.push_back(MakeBinaryRegion( + offset, remaining, BinaryRegionType::Unknown, remaining, 0, + "ERROR: " + name + ". Expected to read " + + std::to_string(type_size) + " bytes.")); + + // TODO(dbaileychess): Should I bail out here? This sets offset to the + // end of the binary. So all other reads in the loop should fail. + offset += remaining; + return; + } + + regions.push_back( + MakeBinaryRegion(offset, type_size, region_type, 0, 0, name)); + + offset += type_size; } else if (field->type()->base_type() == reflection::BaseType::Obj) { // Structs are stored inline, even when nested. offset = BuildStruct(offset, regions, schema_->objects()->Get(field->type()->index())); } else if (field->type()->base_type() == reflection::BaseType::Array) { + const bool is_scalar = IsScalar(field->type()->element()); + const uint64_t type_size = GetTypeSize(field->type()->element()); + const BinaryRegionType region_type = + GetRegionType(field->type()->element()); + // Arrays are just repeated structures. - if (IsScalar(field->type()->element())) { - offset = BuildArrayField(offset, object, field, - field->type()->fixed_length(), regions); - } else { - for (uint16_t i = 0; i < field->type()->fixed_length(); ++i) { + for (uint16_t i = 0; i < field->type()->fixed_length(); ++i) { + if (is_scalar) { + const std::string name = + std::string("array field `") + object->name()->c_str() + "." + + field->name()->c_str() + "[" + std::to_string(i) + "]` (" + + reflection::EnumNameBaseType(field->type()->element()) + ")"; + + if (!IsValidRead(offset, type_size)) { + const uint64_t remaining = RemainingBytes(offset); + regions.push_back(MakeBinaryRegion( + offset, remaining, BinaryRegionType::Unknown, remaining, 0, + "ERROR: " + name + ". Expected to read " + + std::to_string(type_size) + " bytes.")); + + // TODO(dbaileychess): Should I bail out here? This sets offset to + // the end of the binary. So all other reads in the loop should + // fail. + offset += remaining; + break; + } + + regions.push_back( + MakeBinaryRegion(offset, type_size, region_type, 0, 0, name)); + + offset += type_size; + } else { + // Array of Structs. + // // TODO(dbaileychess): This works, but the comments on the fields lose // some context. Need to figure a way how to plumb the nested arrays // comments together that isn't too confusing. @@ -509,57 +784,86 @@ uint64_t BinaryAnnotator::BuildStruct(uint64_t offset, return offset; } -void BinaryAnnotator::BuildString(uint64_t offset, - const reflection::Object *table, - const reflection::Field *field) { +void BinaryAnnotator::BuildString(const uint64_t string_offset, + const reflection::Object *const table, + const reflection::Field *const field) { // Check if we have already generated this string section, and this is a // shared string instance. - if (strings_.find(offset) != strings_.end()) { return; } + if (strings_.find(string_offset) != strings_.end()) { return; } std::vector regions; - const uint32_t string_length = GetScalar(offset); + const auto string_length = ReadScalar(string_offset); - const uint64_t string_soffset = offset; + if (!string_length.has_value()) { + const uint64_t remaining = RemainingBytes(string_offset); - regions.emplace_back(MakeBinaryRegion(offset, sizeof(uint32_t), - BinaryRegionType::Uint32, 0, 0, - std::string("length of string"))); - offset += sizeof(uint32_t); + regions.push_back(MakeBinaryRegion( + string_offset, remaining, BinaryRegionType::Unknown, remaining, 0, + std::string("ERROR: length of string. Incomplete binary, expected to " + "read 4 bytes here"))); - regions.emplace_back(MakeBinaryRegion(offset, string_length * sizeof(char), - BinaryRegionType::Char, string_length, - 0, "")); - offset += string_length * sizeof(char); + } else { + const uint32_t string_size = string_length.value(); + const uint64_t string_end = + string_offset + sizeof(uint32_t) + string_size + sizeof(char); - regions.emplace_back(MakeBinaryRegion(offset, sizeof(char), - BinaryRegionType::Char, 0, 0, - std::string("string terminator"))); - offset += sizeof(char); + if (!IsValidOffset(string_end - 1)) { + regions.push_back(MakeBinaryRegion( + string_offset, sizeof(uint32_t), BinaryRegionType::Uint32, 0, 0, + std::string( + "ERROR: length of string. Length is longer than the binary."))); + } else { + regions.push_back(MakeBinaryRegion(string_offset, sizeof(uint32_t), + BinaryRegionType::Uint32, 0, 0, + "length of string")); - sections_.insert(std::make_pair( - string_soffset, - MakeBinarySection( - std::string(table->name()->c_str()) + "." + field->name()->c_str(), - BinarySectionType::String, std::move(regions)))); + regions.push_back(MakeBinaryRegion(string_offset + sizeof(uint32_t), + string_size, BinaryRegionType::Char, + string_size, 0, "")); + + regions.push_back(MakeBinaryRegion( + string_offset + sizeof(uint32_t) + string_size, sizeof(char), + BinaryRegionType::Char, 0, 0, std::string("string terminator"))); + } + } + + AddSection(string_offset, + MakeBinarySection(std::string(table->name()->c_str()) + "." + + field->name()->c_str(), + BinarySectionType::String, std::move(regions))); // Insert into the strings set to find possible instances of shared strings. - strings_.insert(string_soffset); + strings_.insert(string_offset); } -void BinaryAnnotator::BuildVector(uint64_t offset, - const reflection::Object *table, - const reflection::Field *field, +void BinaryAnnotator::BuildVector(const uint64_t vector_offset, + const reflection::Object *const table, + const reflection::Field *const field, const uint64_t parent_table_offset, const VTable &vtable) { std::vector regions; - const uint32_t vector_length = GetScalar(offset); - const uint64_t vector_offset = offset; + const auto vector_length = ReadScalar(vector_offset); + if (!vector_length.has_value()) { + const uint64_t remaining = RemainingBytes(vector_offset); - regions.emplace_back( - MakeBinaryRegion(offset, sizeof(uint32_t), BinaryRegionType::Uint32, 0, 0, - std::string("length of vector (# items)"))); - offset += sizeof(uint32_t); + AddSection( + vector_offset, + MakeSingleRegionBinarySection( + std::string(table->name()->c_str()) + "." + field->name()->c_str(), + BinarySectionType::Vector, + MakeBinaryRegion(vector_offset, remaining, + BinaryRegionType::Unknown, remaining, 0, + "ERROR: length of vector (# items). Incomplete " + "binary, expected to read 4 bytes here"))); + return; + } + + regions.push_back(MakeBinaryRegion( + vector_offset, sizeof(uint32_t), BinaryRegionType::Uint32, 0, 0, + std::string("length of vector (# items)"))); + + uint64_t offset = vector_offset + sizeof(uint32_t); switch (field->type()->element()) { case reflection::BaseType::Obj: { @@ -568,20 +872,44 @@ void BinaryAnnotator::BuildVector(uint64_t offset, if (object->is_struct()) { // Vector of structs - for (size_t i = 0; i < vector_length; ++i) { + for (size_t i = 0; i < vector_length.value(); ++i) { // Structs are inline to the vector. offset = BuildStruct(offset, regions, object); } } else { // Vector of objects - for (size_t i = 0; i < vector_length; ++i) { - // The table offset is relative from the offset location itself. - const uint64_t table_offset = offset + GetScalar(offset); + for (size_t i = 0; i < vector_length.value(); ++i) { + const std::string name = "offset to table[" + std::to_string(i) + "]"; - regions.emplace_back(MakeBinaryRegion( - offset, sizeof(uint32_t), BinaryRegionType::UOffset, 0, - table_offset, - std::string("offset to table[") + std::to_string(i) + "]")); + const auto table_relative_offset = ReadScalar(offset); + if (!table_relative_offset.has_value()) { + const uint64_t remaining = RemainingBytes(offset); + + regions.push_back(MakeBinaryRegion( + offset, remaining, BinaryRegionType::Unknown, remaining, 0, + "ERROR: " + name + + ". Incomplete binary, expected to " + "read 4 bytes here")); + break; + } + + // The table offset is relative from the offset location itself. + const uint64_t table_offset = offset + table_relative_offset.value(); + + if (!IsValidOffset(table_offset)) { + regions.push_back(MakeBinaryRegion( + offset, sizeof(uint32_t), BinaryRegionType::UOffset, 0, + table_offset, + "ERROR: " + name + + ". Invalid offset, points to outside the binary.")); + + offset += sizeof(uint32_t); + continue; + } + + regions.push_back(MakeBinaryRegion(offset, sizeof(uint32_t), + BinaryRegionType::UOffset, 0, + table_offset, name)); BuildTable(table_offset, BinarySectionType::Table, object); @@ -591,14 +919,38 @@ void BinaryAnnotator::BuildVector(uint64_t offset, } break; case reflection::BaseType::String: { // Vector of strings - for (size_t i = 0; i < vector_length; ++i) { - // The string offset is relative from the offset location itself. - const uint64_t string_offset = offset + GetScalar(offset); + for (size_t i = 0; i < vector_length.value(); ++i) { + const std::string name = "offset to string[" + std::to_string(i) + "]"; - regions.emplace_back(MakeBinaryRegion( - offset, sizeof(uint32_t), BinaryRegionType::UOffset, 0, - string_offset, - std::string("offset to string[") + std::to_string(i) + "]")); + const auto string_relative_offset = ReadScalar(offset); + if (!string_relative_offset.has_value()) { + const uint64_t remaining = RemainingBytes(offset); + + regions.push_back(MakeBinaryRegion( + offset, remaining, BinaryRegionType::Unknown, remaining, 0, + "ERROR: " + name + + ". Incomplete binary, expected to " + "read 4 bytes here")); + break; + } + + // The string offset is relative from the offset location itself. + const uint64_t string_offset = offset + string_relative_offset.value(); + + if (!IsValidOffset(string_offset)) { + regions.push_back(MakeBinaryRegion( + offset, sizeof(uint32_t), BinaryRegionType::UOffset, 0, + string_offset, + "ERROR: " + name + + ". Invalid offset, points to outside the binary.")); + + offset += sizeof(uint32_t); + continue; + } + + regions.push_back(MakeBinaryRegion(offset, sizeof(uint32_t), + BinaryRegionType::UOffset, 0, + string_offset, name)); BuildString(string_offset, table, field); @@ -621,28 +973,81 @@ void BinaryAnnotator::BuildVector(uint64_t offset, const uint64_t union_type_vector_field_offset = parent_table_offset + vtable_entry->second.offset_from_table; + const auto union_type_vector_field_relative_offset = + ReadScalar(union_type_vector_field_offset); + + if (!union_type_vector_field_relative_offset.has_value()) { + const uint64_t remaining = RemainingBytes(offset); + + regions.push_back(MakeBinaryRegion( + offset, remaining, BinaryRegionType::Unknown, remaining, 0, + "ERROR: Union vector offset. Incomplete binary, expected to " + "read 2 bytes here.")); + + break; + } + // Get the offset to the first type (the + sizeof(uint32_t) is to skip - // over the vector length which we already know) + // over the vector length which we already know). Validation happens + // within the loop below. const uint64_t union_type_vector_data_offset = union_type_vector_field_offset + - GetScalar(union_type_vector_field_offset) + - sizeof(uint32_t); + union_type_vector_field_relative_offset.value() + sizeof(uint32_t); + + for (size_t i = 0; i < vector_length.value(); ++i) { + const std::string name = "offset to union[" + std::to_string(i) + "]"; + + const auto union_relative_offset = ReadScalar(offset); + if (!union_relative_offset.has_value()) { + const uint64_t remaining = RemainingBytes(offset); + + regions.push_back(MakeBinaryRegion( + offset, remaining, BinaryRegionType::Unknown, remaining, 0, + "ERROR: " + name + + ". Incomplete binary, expected to " + "read 4 bytes here")); + + break; + } - for (size_t i = 0; i < vector_length; ++i) { // The union offset is relative from the offset location itself. - const uint64_t union_offset = offset + GetScalar(offset); + const uint64_t union_offset = offset + union_relative_offset.value(); - const uint8_t realized_type = GetScalar( - union_type_vector_data_offset + i * sizeof(uint8_t)); + if (!IsValidOffset(union_offset)) { + regions.push_back(MakeBinaryRegion( + offset, sizeof(uint32_t), BinaryRegionType::UOffset, 0, + union_offset, + "ERROR: " + name + + ". Invalid offset, points to outside the binary.")); + continue; + } + + const auto realized_type = + ReadScalar(union_type_vector_data_offset + i); + if (!realized_type.has_value()) { + regions.push_back( + MakeBinaryRegion(offset, 0, BinaryRegionType::Unknown, 0, 0, + "ERROR: " + name + + ". Incomplete binary, expected to " + "read 1 byte here.")); + continue; + } + + if (!IsValidUnionValue(vtable_entry->second.field->type()->index(), + realized_type.value())) { + // We already export an error in the union type field, so just skip + // building the union itself and it will default to an unreference + // Binary section. + offset += sizeof(uint32_t); + continue; + } const std::string enum_type = - BuildUnion(union_offset, realized_type, field); + BuildUnion(union_offset, realized_type.value(), field); - regions.emplace_back(MakeBinaryRegion( + regions.push_back(MakeBinaryRegion( offset, sizeof(uint32_t), BinaryRegionType::UOffset, 0, - union_offset, - std::string("offset to union[") + std::to_string(i) + "] (`" + - enum_type + "`)")); + union_offset, name + " (`" + enum_type + "`)")); offset += sizeof(uint32_t); } @@ -656,10 +1061,39 @@ void BinaryAnnotator::BuildVector(uint64_t offset, // TODO(dbaileychess): It might be nicer to user the // BinaryRegion.array_length field to indicate this. - for (size_t i = 0; i < vector_length; ++i) { - regions.emplace_back(MakeBinaryRegion( - offset, type_size, binary_region_type, 0, 0, - std::string("value[") + std::to_string(i) + "]")); + for (size_t i = 0; i < vector_length.value(); ++i) { + const std::string name = + std::string("value[") + std::to_string(i) + "]"; + if (!IsValidRead(offset, type_size)) { + const uint64_t remaining = RemainingBytes(offset); + + regions.push_back(MakeBinaryRegion( + offset, remaining, BinaryRegionType::Unknown, remaining, 0, + "ERROR: " + name + + ". Incomplete " + "binary, expected to read " + + std::to_string(type_size) + " bytes here")); + break; + } + + if (IsUnionType(field->type()->element())) { + // This is a type for a union. Validate the value + const auto enum_value = ReadScalar(offset); + + // This should alawys have a value, due to the IsValidRead check + // above. + if (!IsValidUnionValue(field->type()->index(), + enum_value.value())) { + regions.push_back(MakeBinaryRegion( + offset, type_size, binary_region_type, 0, 0, + "ERROR: " + name + ". Invalid union type value.")); + offset += type_size; + continue; + } + } + + regions.push_back(MakeBinaryRegion(offset, type_size, + binary_region_type, 0, 0, name)); offset += type_size; } } @@ -673,9 +1107,9 @@ void BinaryAnnotator::BuildVector(uint64_t offset, BinarySectionType::Vector, std::move(regions)))); } -std::string BinaryAnnotator::BuildUnion(uint64_t offset, +std::string BinaryAnnotator::BuildUnion(const uint64_t union_offset, const uint8_t realized_type, - const reflection::Field *field) { + const reflection::Field *const field) { const reflection::Enum *next_enum = schema_->enums()->Get(field->type()->index()); @@ -691,15 +1125,15 @@ std::string BinaryAnnotator::BuildUnion(uint64_t offset, // Union of vectors point to a new Binary section std::vector regions; - offset = BuildStruct(offset, regions, object); + BuildStruct(union_offset, regions, object); - sections_.insert(std::make_pair( - regions[0].offset, + AddSection( + union_offset, MakeBinarySection(std::string(object->name()->c_str()) + "." + field->name()->c_str(), - BinarySectionType::Union, std::move(regions)))); + BinarySectionType::Union, std::move(regions))); } else { - BuildTable(offset, BinarySectionType::Table, object); + BuildTable(union_offset, BinarySectionType::Table, object); } } // TODO(dbaileychess): handle the other union types. @@ -707,6 +1141,47 @@ std::string BinaryAnnotator::BuildUnion(uint64_t offset, return enum_val->name()->c_str(); } +void BinaryAnnotator::FixMissingRegions() { + std::vector regions_to_insert; + for (auto ¤t_section : sections_) { + BinarySection §ion = current_section.second; + if (section.regions.empty()) { + // TODO(dbaileychess): is this possible? + continue; + } + + uint64_t offset = section.regions[0].offset + section.regions[0].length; + for (size_t i = 1; i < section.regions.size(); ++i) { + BinaryRegion ®ion = section.regions[i]; + + const uint64_t next_offset = region.offset; + + if (offset < next_offset) { + const uint64_t padding_bytes = next_offset - offset; + + if (IsNonZeroRegion(offset, padding_bytes, binary_)) { + regions_to_insert.push_back(MakeBinaryRegion( + offset, padding_bytes, BinaryRegionType::Unknown, padding_bytes, + 0, "WARN: nothing refers to this region.")); + } else { + regions_to_insert.push_back( + MakeBinaryRegion(offset, padding_bytes, BinaryRegionType::Uint8, + padding_bytes, 0, "padding")); + } + } + offset = next_offset + region.length; + } + + if (!regions_to_insert.empty()) { + section.regions.insert(section.regions.end(), regions_to_insert.begin(), + regions_to_insert.end()); + std::stable_sort(section.regions.begin(), section.regions.end(), + BinaryRegionSort); + regions_to_insert.clear(); + } + } +} + void BinaryAnnotator::FixMissingSections() { uint64_t offset = 0; @@ -722,44 +1197,20 @@ void BinaryAnnotator::FixMissingSections() { // We are at an offset that is less then the current section. const uint64_t pad_bytes = section_start_offset - offset + 1; - const uint64_t start_offset = offset - 1; - - std::vector regions; - - // Check if the region is all zeros or not, as that can tell us if it is - // padding or not. - if (IsNonZeroRegion(offset - 1, pad_bytes, binary_)) { - // Some of the padding bytes are non-zero, so this might be an unknown - // section of the binary. - regions.emplace_back(MakeBinaryRegion( - start_offset, pad_bytes * sizeof(uint8_t), - BinaryRegionType::Unknown, pad_bytes, 0, - pad_bytes < 8 ? "could be a corrupted padding region (non zero) " - "due to the length < 8 bytes." - : "WARN: nothing refers to this. Check if any " - "`Unkown Field`s point to this.")); - - sections_to_insert.emplace_back( - MakeBinarySection("no known references", BinarySectionType::Unknown, - std::move(regions))); - } else { - // This region is most likely padding. - regions.emplace_back(MakeBinaryRegion( - start_offset, pad_bytes * sizeof(uint8_t), BinaryRegionType::Uint8, - pad_bytes, 0, - // Output a different annotation if the pad bytes exceed what we - // expect to be the maximum padding. - pad_bytes > 7 ? "likely padding but might be an unknown section " - "due to being larger than 7 bytes" - : "padding")); - - sections_to_insert.emplace_back(MakeBinarySection( - "", BinarySectionType::Padding, std::move(regions))); - } + sections_to_insert.push_back( + GenerateMissingSection(offset - 1, pad_bytes, binary_)); } offset = section_end_offset + 1; } + // Handle the case where there are still bytes left in the binary that are + // unaccounted for. + if (offset < binary_length_) { + const uint64_t pad_bytes = binary_length_ - offset + 1; + sections_to_insert.push_back( + GenerateMissingSection(offset - 1, pad_bytes, binary_)); + } + for (const BinarySection §ion_to_insert : sections_to_insert) { sections_.insert( std::make_pair(section_to_insert.regions[0].offset, section_to_insert)); diff --git a/src/binary_annotator.h b/src/binary_annotator.h index 5544e94d7..050021761 100644 --- a/src/binary_annotator.h +++ b/src/binary_annotator.h @@ -18,9 +18,12 @@ #define FLATBUFFERS_BINARY_ANNOTATOR_H_ #include +#include #include +#include "flatbuffers/base.h" #include "flatbuffers/reflection.h" +#include "flatbuffers/stl_emulation.h" namespace flatbuffers { @@ -41,7 +44,8 @@ enum class BinaryRegionType { Uint64 = 13, Int64 = 14, Float = 15, - Double = 16 + Double = 16, + UType = 17, }; template static inline T GetScalar(const uint8_t *binary) { @@ -114,7 +118,7 @@ struct BinarySection { inline static BinaryRegionType GetRegionType(reflection::BaseType base_type) { switch (base_type) { - case reflection::UType: return BinaryRegionType::Uint8; + case reflection::UType: return BinaryRegionType::UType; case reflection::Bool: return BinaryRegionType::Uint8; case reflection::Byte: return BinaryRegionType::Uint8; case reflection::UByte: return BinaryRegionType::Uint8; @@ -148,6 +152,7 @@ inline static std::string ToString(const BinaryRegionType type) { case BinaryRegionType::Int64: return "int64_t"; case BinaryRegionType::Double: return "double"; case BinaryRegionType::Float: return "float"; + case BinaryRegionType::UType: return "UType8"; case BinaryRegionType::Unknown: return "?uint8_t"; default: return "todo"; } @@ -155,12 +160,15 @@ inline static std::string ToString(const BinaryRegionType type) { class BinaryAnnotator { public: - explicit BinaryAnnotator(const uint8_t *const bfbs, const int64_t bfbs_length, - const uint8_t *const binary) + explicit BinaryAnnotator(const uint8_t *const bfbs, + const uint64_t bfbs_length, + const uint8_t *const binary, + const uint64_t binary_length) : bfbs_(bfbs), bfbs_length_(bfbs_length), schema_(reflection::GetSchema(bfbs)), - binary_(binary) {} + binary_(binary), + binary_length_(binary_length) {} std::map Annotate(); @@ -180,7 +188,8 @@ class BinaryAnnotator { uint64_t BuildHeader(uint64_t offset); - void BuildVTable(uint64_t offset, const reflection::Object *table); + void BuildVTable(uint64_t offset, const reflection::Object *table, + uint64_t offset_of_referring_table); void BuildTable(uint64_t offset, const BinarySectionType type, const reflection::Object *table); @@ -198,19 +207,84 @@ class BinaryAnnotator { std::string BuildUnion(uint64_t offset, uint8_t realized_type, const reflection::Field *field); + void FixMissingRegions(); void FixMissingSections(); - template inline T GetScalar(uint64_t offset) { - return *reinterpret_cast(binary_ + offset); + inline bool IsValidOffset(const uint64_t offset) const { + return offset < binary_length_; + } + + // Determines if performing a GetScalar request for `T` at `offset` would read + // passed the end of the binary. + template inline bool IsValidRead(const uint64_t offset) const { + return IsValidRead(offset, sizeof(T)); + } + + inline bool IsValidRead(const uint64_t offset, const uint64_t length) const { + return IsValidOffset(offset + length - 1); + } + + // Calculate the number of bytes remaining from the given offset. If offset is + // > binary_length, 0 is returned. + uint64_t RemainingBytes(const uint64_t offset) const { + return IsValidOffset(offset) ? binary_length_ - offset : 0; + } + + template + flatbuffers::Optional ReadScalar(const uint64_t offset) const { + if (!IsValidRead(offset)) { return flatbuffers::nullopt; } + + return flatbuffers::ReadScalar(binary_ + offset); + } + + // Adds the provided `section` keyed by the `offset` it occurs at. If a + // section is already added at that offset, it doesn't replace the exisiting + // one. + void AddSection(const uint64_t offset, const BinarySection §ion) { + sections_.insert(std::make_pair(offset, section)); + } + + bool IsInlineField(const reflection::Field *const field) { + if (field->type()->base_type() == reflection::BaseType::Obj) { + return schema_->objects()->Get(field->type()->index())->is_struct(); + } + return IsScalar(field->type()->base_type()); + } + + bool IsUnionType(const reflection::BaseType type) { + return (type == reflection::BaseType::UType || + type == reflection::BaseType::Union); + } + + bool IsUnionType(const reflection::Field *const field) { + return IsUnionType(field->type()->base_type()) && + field->type()->index() >= 0; + } + + bool IsValidUnionValue(const reflection::Field *const field, + const uint8_t value) { + return IsUnionType(field) && + IsValidUnionValue(field->type()->index(), value); + } + + bool IsValidUnionValue(const uint32_t enum_id, const uint8_t value) { + if (enum_id >= schema_->enums()->size()) { return false; } + + const reflection::Enum *enum_def = schema_->enums()->Get(enum_id); + + if (enum_def == nullptr) { return false; } + + return value < enum_def->values()->size(); } // The schema for the binary file const uint8_t *bfbs_; - const int64_t bfbs_length_; + const uint64_t bfbs_length_; const reflection::Schema *schema_; // The binary data itself. const uint8_t *binary_; + const uint64_t binary_length_; // Map of binary offset to vtables, to dedupe vtables. std::map vtables_; diff --git a/src/flatc.cpp b/src/flatc.cpp index c68e9baac..1f0e6e114 100644 --- a/src/flatc.cpp +++ b/src/flatc.cpp @@ -350,8 +350,8 @@ void FlatCompiler::AnnotateBinaries( reinterpret_cast(binary_contents.c_str()); const size_t binary_size = binary_contents.size(); - flatbuffers::BinaryAnnotator binary_annotator(binary_schema, - binary_schema_size, binary); + flatbuffers::BinaryAnnotator binary_annotator( + binary_schema, binary_schema_size, binary, binary_size); auto annotations = binary_annotator.Annotate(); diff --git a/tests/annotated_binary/annotated_binary.afb b/tests/annotated_binary/annotated_binary.afb index 804d112ad..469bb3e61 100644 --- a/tests/annotated_binary/annotated_binary.afb +++ b/tests/annotated_binary/annotated_binary.afb @@ -46,11 +46,11 @@ root_table (AnnotatedBinary.Foo): +0x0048 | 00 00 00 | uint8_t[3] | ... | padding +0x004B | 01 | uint8_t | 0x01 (1) | table field `healthy` (Bool) +0x004C | 02 | uint8_t | 0x02 (2) | table field `meal` (Byte) - +0x004D | 02 | uint8_t | 0x02 (2) | table field `bar_baz_type` (UType) - +0x004E | 01 | uint8_t | 0x01 (1) | table field `measurement_type` (UType) - +0x004F | 01 | uint8_t | 0x01 (1) | table field `anything_type` (UType) + +0x004D | 02 | UType8 | 0x02 (2) | table field `bar_baz_type` (UType) + +0x004E | 01 | UType8 | 0x01 (1) | table field `measurement_type` (UType) + +0x004F | 01 | UType8 | 0x01 (1) | table field `anything_type` (UType) +0x0050 | D2 04 00 00 | uint32_t | 0x000004D2 (1234) | table field `counter` (Int) - +0x0054 | 28 02 00 00 | UOffset32 | 0x00000228 (552) Loc: +0x027C | offset to field `bar` + +0x0054 | 28 02 00 00 | UOffset32 | 0x00000228 (552) Loc: +0x027C | offset to field `bar` (table) +0x0058 | 01 00 00 00 | uint32_t | 0x00000001 (1) | struct field `AnnotatedBinary.Building.floors` (Int) +0x005C | 02 00 00 00 | uint32_t | 0x00000002 (2) | struct field `AnnotatedBinary.Building.doors` (Int) +0x0060 | 0C 00 00 00 | uint32_t | 0x0000000C (12) | struct field `AnnotatedBinary.Building.windows` (Int) @@ -61,20 +61,20 @@ root_table (AnnotatedBinary.Foo): +0x0071 | 02 | uint8_t | 0x02 (2) | struct field `AnnotatedBinary.Tolerance.width` (UByte) +0x0072 | 03 | uint8_t | 0x03 (3) | struct field `AnnotatedBinary.Tolerance.width` (UByte) +0x0073 | 00 | uint8_t[1] | . | padding - +0x0074 | C8 01 00 00 | UOffset32 | 0x000001C8 (456) Loc: +0x023C | offset to field `name` - +0x0078 | 5C 01 00 00 | UOffset32 | 0x0000015C (348) Loc: +0x01D4 | offset to field `bars` + +0x0074 | C8 01 00 00 | UOffset32 | 0x000001C8 (456) Loc: +0x023C | offset to field `name` (string) + +0x0078 | 5C 01 00 00 | UOffset32 | 0x0000015C (348) Loc: +0x01D4 | offset to field `bars` (vector) +0x007C | 50 01 00 00 | UOffset32 | 0x00000150 (336) Loc: +0x01CC | offset to field `bar_baz` (union of type `Baz`) - +0x0080 | 34 01 00 00 | UOffset32 | 0x00000134 (308) Loc: +0x01B4 | offset to field `accounts` - +0x0084 | 24 01 00 00 | UOffset32 | 0x00000124 (292) Loc: +0x01A8 | offset to field `bob` - +0x0088 | 14 01 00 00 | UOffset32 | 0x00000114 (276) Loc: +0x019C | offset to field `alice` + +0x0080 | 34 01 00 00 | UOffset32 | 0x00000134 (308) Loc: +0x01B4 | offset to field `accounts` (vector) + +0x0084 | 24 01 00 00 | UOffset32 | 0x00000124 (292) Loc: +0x01A8 | offset to field `bob` (string) + +0x0088 | 14 01 00 00 | UOffset32 | 0x00000114 (276) Loc: +0x019C | offset to field `alice` (string) +0x008C | 0D 00 00 00 | uint32_t | 0x0000000D (13) | table field `just_i32` (Int) - +0x0090 | DC 00 00 00 | UOffset32 | 0x000000DC (220) Loc: +0x016C | offset to field `names` - +0x0094 | A0 00 00 00 | UOffset32 | 0x000000A0 (160) Loc: +0x0134 | offset to field `points_of_interest` - +0x0098 | 94 00 00 00 | UOffset32 | 0x00000094 (148) Loc: +0x012C | offset to field `foobars_type` - +0x009C | 38 00 00 00 | UOffset32 | 0x00000038 (56) Loc: +0x00D4 | offset to field `foobars` + +0x0090 | DC 00 00 00 | UOffset32 | 0x000000DC (220) Loc: +0x016C | offset to field `names` (vector) + +0x0094 | A0 00 00 00 | UOffset32 | 0x000000A0 (160) Loc: +0x0134 | offset to field `points_of_interest` (vector) + +0x0098 | 94 00 00 00 | UOffset32 | 0x00000094 (148) Loc: +0x012C | offset to field `foobars_type` (vector) + +0x009C | 38 00 00 00 | UOffset32 | 0x00000038 (56) Loc: +0x00D4 | offset to field `foobars` (vector) +0x00A0 | 33 00 00 00 | UOffset32 | 0x00000033 (51) Loc: +0x00D3 | offset to field `measurement` (union of type `Tolerance`) +0x00A4 | 1C 00 00 00 | UOffset32 | 0x0000001C (28) Loc: +0x00C0 | offset to field `anything` (union of type `Bar`) - +0x00A8 | 04 00 00 00 | UOffset32 | 0x00000004 (4) Loc: +0x00AC | offset to field `charlie` + +0x00A8 | 04 00 00 00 | UOffset32 | 0x00000004 (4) Loc: +0x00AC | offset to field `charlie` (string) string (AnnotatedBinary.Foo.charlie): +0x00AC | 05 00 00 00 | uint32_t | 0x00000005 (5) | length of string @@ -108,7 +108,7 @@ vector (AnnotatedBinary.Foo.foobars): table (AnnotatedBinary.Bar): +0x00E4 | D2 FE FF FF | SOffset32 | 0xFFFFFED2 (-302) Loc: +0x0212 | offset to vtable +0x00E8 | 00 80 23 44 | float | 0x44238000 (654.000000) | table field `b` (Float) - +0x00EC | 10 00 00 00 | UOffset32 | 0x00000010 (16) Loc: +0x00FC | offset to field `c` + +0x00EC | 10 00 00 00 | UOffset32 | 0x00000010 (16) Loc: +0x00FC | offset to field `c` (table) +0x00F0 | 00 00 00 00 00 D8 8E 40 | double | 0x408ED80000000000 (987.000000) | table field `a` (Double) +0x00F8 | 00 00 00 00 | uint8_t[4] | .... | padding @@ -127,7 +127,7 @@ table (AnnotatedBinary.Baz): table (AnnotatedBinary.Bar): +0x010C | FA FE FF FF | SOffset32 | 0xFFFFFEFA (-262) Loc: +0x0212 | offset to vtable +0x0110 | 00 00 E4 43 | float | 0x43E40000 (456.000000) | table field `b` (Float) - +0x0114 | 10 00 00 00 | UOffset32 | 0x00000010 (16) Loc: +0x0124 | offset to field `c` + +0x0114 | 10 00 00 00 | UOffset32 | 0x00000010 (16) Loc: +0x0124 | offset to field `c` (table) +0x0118 | 00 00 00 00 00 C0 5E 40 | double | 0x405EC00000000000 (123.000000) | table field `a` (Double) +0x0120 | 00 00 00 00 | uint8_t[4] | .... | padding @@ -138,9 +138,9 @@ table (AnnotatedBinary.Baz): vector (AnnotatedBinary.Foo.foobars_type): +0x012C | 03 00 00 00 | uint32_t | 0x00000003 (3) | length of vector (# items) - +0x0130 | 01 | uint8_t | 0x01 (1) | value[0] - +0x0131 | 02 | uint8_t | 0x02 (2) | value[1] - +0x0132 | 01 | uint8_t | 0x01 (1) | value[2] + +0x0130 | 01 | UType8 | 0x01 (1) | value[0] + +0x0131 | 02 | UType8 | 0x02 (2) | value[1] + +0x0132 | 01 | UType8 | 0x01 (1) | value[2] vector (AnnotatedBinary.Foo.points_of_interest): +0x0134 | 03 00 00 00 | uint32_t | 0x00000003 (3) | length of vector (# items) @@ -226,7 +226,7 @@ vtable (AnnotatedBinary.Bar): table (AnnotatedBinary.Bar): +0x01EC | 0A 00 00 00 | SOffset32 | 0x0000000A (10) Loc: +0x01E2 | offset to vtable +0x01F0 | 00 80 23 44 | float | 0x44238000 (654.000000) | table field `b` (Float) - +0x01F4 | 18 00 00 00 | UOffset32 | 0x00000018 (24) Loc: +0x020C | offset to field `c` + +0x01F4 | 18 00 00 00 | UOffset32 | 0x00000018 (24) Loc: +0x020C | offset to field `c` (table) +0x01F8 | 00 00 00 00 00 D8 8E 40 | double | 0x408ED80000000000 (987.000000) | table field `a` (Double) +0x0200 | 00 00 00 00 00 00 | uint8_t[6] | ...... | padding @@ -250,7 +250,7 @@ vtable (AnnotatedBinary.Bar): table (AnnotatedBinary.Bar): +0x021C | 0A 00 00 00 | SOffset32 | 0x0000000A (10) Loc: +0x0212 | offset to vtable +0x0220 | 00 00 E4 43 | float | 0x43E40000 (456.000000) | table field `b` (Float) - +0x0224 | 10 00 00 00 | UOffset32 | 0x00000010 (16) Loc: +0x0234 | offset to field `c` + +0x0224 | 10 00 00 00 | UOffset32 | 0x00000010 (16) Loc: +0x0234 | offset to field `c` (table) +0x0228 | 00 00 00 00 00 C0 5E 40 | double | 0x405EC00000000000 (123.000000) | table field `a` (Double) +0x0230 | 00 00 00 00 | uint8_t[4] | .... | padding @@ -282,7 +282,7 @@ vtable (AnnotatedBinary.Bar): table (AnnotatedBinary.Bar): +0x027C | 0A 00 00 00 | SOffset32 | 0x0000000A (10) Loc: +0x0272 | offset to vtable +0x0280 | 65 20 71 49 | float | 0x49712065 (987654.312500) | table field `b` (Float) - +0x0284 | 14 00 00 00 | UOffset32 | 0x00000014 (20) Loc: +0x0298 | offset to field `c` + +0x0284 | 14 00 00 00 | UOffset32 | 0x00000014 (20) Loc: +0x0298 | offset to field `c` (table) +0x0288 | C9 76 BE 9F 0C 24 FE 40 | double | 0x40FE240C9FBE76C9 (123456.789000) | table field `a` (Double) +0x0290 | 00 00 | uint8_t[2] | .. | padding diff --git a/tests/annotated_binary/generate_annotations.py b/tests/annotated_binary/generate_annotations.py new file mode 100755 index 000000000..bd5de2b28 --- /dev/null +++ b/tests/annotated_binary/generate_annotations.py @@ -0,0 +1,76 @@ +#!/usr/bin/env python3 +# +# Copyright 2021 Google Inc. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import platform +import subprocess +from pathlib import Path + +# Get the path where this script is located so we can invoke the script from +# any directory and have the paths work correctly. +script_path = Path(__file__).parent.resolve() + +# Get the root path as an absolute path, so all derived paths are absolute. +root_path = script_path.parent.parent.absolute() + +# Get the location of the flatc executable, reading from the first command line +# argument or defaulting to default names. +flatc_exe = Path( + ("flatc" if not platform.system() == "Windows" else "flatc.exe") +) + +# Find and assert flatc compiler is present. +if root_path in flatc_exe.parents: + flatc_exe = flatc_exe.relative_to(root_path) +flatc_path = Path(root_path, flatc_exe) +assert flatc_path.exists(), "Cannot find the flatc compiler " + str(flatc_path) + +# Specify the other paths that will be referenced +tests_path = Path(script_path, "tests") + + +def flatc_annotate(schema, file, cwd=script_path): + cmd = [str(flatc_path), "--annotate", schema, file] + result = subprocess.run(cmd, cwd=str(cwd), check=True) + + +test_files = [ + "annotated_binary.bin", + "tests/invalid_root_offset.bin", + "tests/invalid_root_table_too_short.bin", + "tests/invalid_root_table_vtable_offset.bin", + "tests/invalid_string_length.bin", + "tests/invalid_string_length_cut_short.bin", + "tests/invalid_struct_array_field_cut_short.bin", + "tests/invalid_struct_field_cut_short.bin", + "tests/invalid_table_field_size.bin", + "tests/invalid_table_field_offset.bin", + "tests/invalid_union_type_value.bin", + "tests/invalid_vector_length_cut_short.bin", + "tests/invalid_vector_scalars_cut_short.bin", + "tests/invalid_vector_strings_cut_short.bin", + "tests/invalid_vector_structs_cut_short.bin", + "tests/invalid_vector_tables_cut_short.bin", + "tests/invalid_vector_unions_cut_short.bin", + "tests/invalid_vector_union_type_value.bin", + "tests/invalid_vtable_ref_table_size_short.bin", + "tests/invalid_vtable_ref_table_size.bin", + "tests/invalid_vtable_size_short.bin", + "tests/invalid_vtable_size.bin", + "tests/invalid_vtable_field_offset.bin", +] + +for test_file in test_files: + flatc_annotate("annotated_binary.fbs", test_file) diff --git a/tests/annotated_binary/tests/README.md b/tests/annotated_binary/tests/README.md new file mode 100644 index 000000000..c0d73f499 --- /dev/null +++ b/tests/annotated_binary/tests/README.md @@ -0,0 +1,125 @@ +# Tests for Annotated Binaries + +## Invalid Binary Tests + +The following is a collection of manually corrupted binaries based off of +`..\annotated_binary.bin`. Each file changes some offset or length/size entry to +point so an invalid spot, and the generated annotated binaries demonstrate that +those corruptions can be spotted. + +Each of these files were ran with the following command: + +```sh +cd .tests/annotated_binary +../../flatc -annotate annotated_binary.fbs tests/{binary_file}... +``` + +### `invalid_root_offset.bin` + +Changed first two bytes from `4400` to `FFFF` which produces an offset larger +than the binary. + +### `invalid_root_table_vtable_offset.bin` + +Changed two bytes at 0x0044 from `3A00` to `FFFF` which points to an offset +outside the binary. + +### `invalid_root_table_too_short.bin` + +Truncated the file to 0x46 bytes, as that cuts into the vtable offset field of +the root table. + +```sh +truncate annotated_binary.bin --size=70 >> invalid_root_table_too_short.bin +``` + +### `invalid_vtable_size.bin` + +Changed two bytes at 0x000A from `3A00` to `FFFF` which size is larger than the +binary. + +### `invalid_vtable_size_short.bin` + +Changed two bytes at 0x000A from `3A00` to `0100` which size is smaller than the +minimum size of 4 bytes. + +### `invalid_vtable_ref_table_size.bin` + +Changed two bytes at 0x000C from `6800` to `FFFF` which size is larger than the +binary. + +### `invalid_vtable_ref_table_size_short.bin` + +Changed two bytes at 0x000C from `6800` to `0100` which size is smaller than +the minimum size of 4 bytes. + +### `invalid_vtable_field_offset.bin` + +Changed two bytes at 0x0016 from `1000` to `FFFF` which points to a field larger +than the binary. + +### `invalid_table_field_size.bin` + +Truncated the file to 0x52 bytes, as that cuts a Uint32t value in half. + +### `invalid_table_field_offset.bin` + +Truncated the file to 0x96 bytes, as that cuts a UOffset32 value in half. Also, +changed two bytes at 0x90 from `DC00` to `FFFF` which points to a section larger +than the binary. + +### `invalid_string_length_cut_short.bin` + +Truncated the file to 0xAD bytes, as that cuts string length Uint32t value in +half. + +### `invalid_string_length.bin` + +Changed two bytes at 0x00AC from `0500` to `FFFF` which is a string length +larger than the binary. + +### `invalid_vector_length_cut_short.bin` + +Truncated the file to 0x0136 bytes, as that cuts vector length Uint32t value in +half. + +### `invalid_struct_field_cut_short.bin` + +Truncated the file to 0x5d bytes, as that cuts struct field value in half. + +### `invalid_struct_array_field_cut_short.bin` + +Truncated the file to 0x6A bytes, as that cuts struct array field value in half. + +### `invalid_vector_structs_cut_short.bin` + +Truncated the file to 0x0154 bytes, as that cuts into a vector of structs. + +### `invalid_vector_tables_cut_short.bin` + +Truncated the file to 0x01DE bytes, as that cuts into a vector of table offsets. + +### `invalid_vector_strings_cut_short.bin` + +Truncated the file to 0x0176 bytes, as that cuts into a vector of string +offsets. + +### `invalid_vector_scalars_cut_short.bin` + +Truncated the file to 0x01C1 bytes, as that cuts into a vector of scalars +values. + +### `invalid_vector_unions_cut_short.bin` + +Truncated the file to 0x01DE bytes, as that cuts into a vector of union offset +values. + +### `invalid_union_type_value.bin` + +Changed one byte at 0x004D from `02` to `FF` which is a union type value that is +larger than the enum. + +### `invalid_vector_union_type_value.bin` + +Changed one byte at 0x0131 from `02` to `FF` which is a vector union type value +that is larger than the enum. \ No newline at end of file diff --git a/tests/annotated_binary/tests/invalid_root_offset.afb b/tests/annotated_binary/tests/invalid_root_offset.afb new file mode 100644 index 000000000..692b04a7b --- /dev/null +++ b/tests/annotated_binary/tests/invalid_root_offset.afb @@ -0,0 +1,93 @@ +// Annotated Flatbuffer Binary +// +// Schema file: annotated_binary.fbs +// Binary file: tests/invalid_root_offset.bin + +header: + +0x0000 | FF FF 00 00 | UOffset32 | 0x0000FFFF (65535) Loc: +0xFFFF | ERROR: offset to root table `AnnotatedBinary.Foo`. Invalid offset, points to outside the binary. + +0x0004 | 41 4E 4E 4F | char[4] | ANNO | File Identifier + +unknown (no known references): + +0x0008 | 00 00 3A 00 68 00 0C 00 | ?uint8_t[664] | ..:.h... | WARN: nothing refers to this section. + +0x0010 | 07 00 00 00 08 00 10 00 | | ........ + +0x0018 | 14 00 30 00 34 00 09 00 | | ..0.4... + +0x0020 | 38 00 3C 00 40 00 44 00 | | 8.<.@.D. + +0x0028 | 00 00 00 00 48 00 4C 00 | | ....H.L. + +0x0030 | 50 00 54 00 58 00 0A 00 | | P.T.X... + +0x0038 | 5C 00 0B 00 60 00 00 00 | | \...`... + +0x0040 | 00 00 64 00 3A 00 00 00 | | ..d.:... + +0x0048 | 00 00 00 01 02 02 01 01 | | ........ + +0x0050 | D2 04 00 00 28 02 00 00 | | ....(... + +0x0058 | 01 00 00 00 02 00 00 00 | | ........ + +0x0060 | 0C 00 00 00 0A 00 00 00 | | ........ + +0x0068 | 0C 00 00 00 14 00 00 00 | | ........ + +0x0070 | 01 02 03 00 C8 01 00 00 | | ........ + +0x0078 | 5C 01 00 00 50 01 00 00 | | \...P... + +0x0080 | 34 01 00 00 24 01 00 00 | | 4...$... + +0x0088 | 14 01 00 00 0D 00 00 00 | | ........ + +0x0090 | DC 00 00 00 A0 00 00 00 | | ........ + +0x0098 | 94 00 00 00 38 00 00 00 | | ....8... + +0x00A0 | 33 00 00 00 1C 00 00 00 | | 3....... + +0x00A8 | 04 00 00 00 05 00 00 00 | | ........ + +0x00B0 | 61 6C 69 63 65 00 00 00 | | alice... + +0x00B8 | 08 00 13 00 08 00 04 00 | | ........ + +0x00C0 | 08 00 00 00 00 80 23 44 | | ......#D + +0x00C8 | 00 00 00 00 00 10 74 40 | | ......t@ + +0x00D0 | 00 00 00 05 03 00 00 00 | | ........ + +0x00D8 | 34 00 00 00 2C 00 00 00 | | 4...,... + +0x00E0 | 04 00 00 00 D2 FE FF FF | | ........ + +0x00E8 | 00 80 23 44 10 00 00 00 | | ..#D.... + +0x00F0 | 00 00 00 00 00 D8 8E 40 | | .......@ + +0x00F8 | 00 00 00 00 6A FE FF FF | | ....j... + +0x0100 | 00 00 00 03 04 00 04 00 | | ........ + +0x0108 | 04 00 00 00 FA FE FF FF | | ........ + +0x0110 | 00 00 E4 43 10 00 00 00 | | ...C.... + +0x0118 | 00 00 00 00 00 C0 5E 40 | | ......^@ + +0x0120 | 00 00 00 00 92 FE FF FF | | ........ + +0x0128 | 00 00 00 01 03 00 00 00 | | ........ + +0x0130 | 01 02 01 00 03 00 00 00 | | ........ + +0x0138 | 33 33 33 33 33 A3 45 40 | | 33333.E@ + +0x0140 | 7E 57 04 FF 5B 87 53 C0 | | ~W..[.S. + +0x0148 | 8D F0 F6 20 04 B6 42 40 | | ... ..B@ + +0x0150 | 9F 77 63 41 61 85 5E C0 | | .wcAa.^. + +0x0158 | 8F 35 23 83 DC 35 4B C0 | | .5#..5K. + +0x0160 | F6 97 DD 93 87 C5 0A 40 | | .......@ + +0x0168 | 00 00 00 00 03 00 00 00 | | ........ + +0x0170 | 20 00 00 00 14 00 00 00 | | ....... + +0x0178 | 04 00 00 00 07 00 00 00 | | ........ + +0x0180 | 63 68 61 72 6C 69 65 00 | | charlie. + +0x0188 | 03 00 00 00 62 6F 62 00 | | ....bob. + +0x0190 | 05 00 00 00 61 6C 69 63 | | ....alic + +0x0198 | 65 00 00 00 07 00 00 00 | | e....... + +0x01A0 | 63 68 61 72 6C 69 65 00 | | charlie. + +0x01A8 | 07 00 00 00 63 68 61 72 | | ....char + +0x01B0 | 6C 69 65 00 09 00 00 00 | | lie..... + +0x01B8 | 09 00 08 00 07 00 01 00 | | ........ + +0x01C0 | 02 00 03 00 06 00 05 00 | | ........ + +0x01C8 | 04 00 00 00 3A FF FF FF | | ....:... + +0x01D0 | 00 00 00 03 02 00 00 00 | | ........ + +0x01D8 | 44 00 00 00 10 00 00 00 | | D....... + +0x01E0 | 00 00 0A 00 1A 00 0C 00 | | ........ + +0x01E8 | 04 00 08 00 0A 00 00 00 | | ........ + +0x01F0 | 00 80 23 44 18 00 00 00 | | ..#D.... + +0x01F8 | 00 00 00 00 00 D8 8E 40 | | .......@ + +0x0200 | 00 00 00 00 00 00 06 00 | | ........ + +0x0208 | 06 00 05 00 06 00 00 00 | | ........ + +0x0210 | 00 03 0A 00 18 00 0C 00 | | ........ + +0x0218 | 04 00 08 00 0A 00 00 00 | | ........ + +0x0220 | 00 00 E4 43 10 00 00 00 | | ...C.... + +0x0228 | 00 00 00 00 00 C0 5E 40 | | ......^@ + +0x0230 | 00 00 00 00 A2 FF FF FF | | ........ + +0x0238 | 00 00 00 01 2F 00 00 00 | | ..../... + +0x0240 | 54 68 69 73 20 69 73 20 | | This is + +0x0248 | 61 20 6C 6F 6E 67 20 73 | | a long s + +0x0250 | 74 72 69 6E 67 20 74 6F | | tring to + +0x0258 | 20 73 68 6F 77 20 68 6F | | show ho + +0x0260 | 77 20 69 74 20 62 72 65 | | w it bre + +0x0268 | 61 6B 73 20 75 70 2E 00 | | aks up.. + +0x0270 | 00 00 0A 00 16 00 0C 00 | | ........ + +0x0278 | 04 00 08 00 0A 00 00 00 | | ........ + +0x0280 | 65 20 71 49 14 00 00 00 | | e qI.... + +0x0288 | C9 76 BE 9F 0C 24 FE 40 | | .v...$.@ + +0x0290 | 00 00 06 00 08 00 07 00 | | ........ + +0x0298 | 06 00 00 00 00 00 00 01 | | ........ diff --git a/tests/annotated_binary/tests/invalid_root_offset.bin b/tests/annotated_binary/tests/invalid_root_offset.bin new file mode 100644 index 0000000000000000000000000000000000000000..c539a01be45961d8f298996a9b0927dd47ee082c GIT binary patch literal 672 zcmZXR&nrYx6vw~!&BM$?O_?NF++txNl$nw&o?k_Tq9~F#V=|A)Ff+_fO0q(sEQ$ZY zQnOKPtt{C21FS48Jm2%4G;(^MckVs+ob&GaKFAfsfHEBZLPYE|O^yCv7A~ z>UsV`uE;s*B|W5tuq~>HlXX*R`Y;-ZNoaem!3Cp5o4cwIUvbhwr0(g<^CTzAwQtYI zw)i!P10j=HlK1KF--dqk%1buGI1TcY^i_s}_#UyF5qo#e^cD_h%17@X+PodKFH5Nb z=U}OPl4#w3NsO02E?&cJvu@fyOXiY)W~@A~Tt`?J;p8<` z*SFqA z#w}<*j?U&bR&}A6cj<~bUC880T5yXxnNK_G1--r5$qEaN75&qCYfSWb+_}4~Yx}b0 LE;5;a7s~w&%bsi? literal 0 HcmV?d00001 diff --git a/tests/annotated_binary/tests/invalid_root_table_too_short.afb b/tests/annotated_binary/tests/invalid_root_table_too_short.afb new file mode 100644 index 000000000..66bb9e99b --- /dev/null +++ b/tests/annotated_binary/tests/invalid_root_table_too_short.afb @@ -0,0 +1,21 @@ +// Annotated Flatbuffer Binary +// +// Schema file: annotated_binary.fbs +// Binary file: tests/invalid_root_table_too_short.bin + +header: + +0x00 | 44 00 00 00 | UOffset32 | 0x00000044 (68) Loc: +0x44 | offset to root table `AnnotatedBinary.Foo` + +0x04 | 41 4E 4E 4F | char[4] | ANNO | File Identifier + +unknown (no known references): + +0x08 | 00 00 3A 00 68 00 0C 00 | ?uint8_t[60] | ..:.h... | WARN: nothing refers to this section. + +0x10 | 07 00 00 00 08 00 10 00 | | ........ + +0x18 | 14 00 30 00 34 00 09 00 | | ..0.4... + +0x20 | 38 00 3C 00 40 00 44 00 | | 8.<.@.D. + +0x28 | 00 00 00 00 48 00 4C 00 | | ....H.L. + +0x30 | 50 00 54 00 58 00 0A 00 | | P.T.X... + +0x38 | 5C 00 0B 00 60 00 00 00 | | \...`... + +0x40 | 00 00 64 00 | | ..d. + +root_table (AnnotatedBinary.Foo): + +0x44 | 3A 00 | ?uint8_t[2] | :. | ERROR: offset to vtable. Incomplete binary, expected to read 4 bytes here diff --git a/tests/annotated_binary/tests/invalid_root_table_too_short.bin b/tests/annotated_binary/tests/invalid_root_table_too_short.bin new file mode 100644 index 0000000000000000000000000000000000000000..bb1c7fcc0a44de9b05a0ed5ed03b1407aecec68a GIT binary patch literal 70 zcmZ=^U|?|c^Ydq5uwuwy;9+0~@;Mj;7(^Hh7)%&A87vrV7#tW}fT9cx9t=JV0SqAw S5e!@mF$~-c31HC_piThsxdyfX literal 0 HcmV?d00001 diff --git a/tests/annotated_binary/tests/invalid_root_table_vtable_offset.afb b/tests/annotated_binary/tests/invalid_root_table_vtable_offset.afb new file mode 100644 index 000000000..34dbdf874 --- /dev/null +++ b/tests/annotated_binary/tests/invalid_root_table_vtable_offset.afb @@ -0,0 +1,98 @@ +// Annotated Flatbuffer Binary +// +// Schema file: annotated_binary.fbs +// Binary file: tests/invalid_root_table_vtable_offset.bin + +header: + +0x0000 | 44 00 00 00 | UOffset32 | 0x00000044 (68) Loc: +0x0044 | offset to root table `AnnotatedBinary.Foo` + +0x0004 | 41 4E 4E 4F | char[4] | ANNO | File Identifier + +unknown (no known references): + +0x0008 | 00 00 3A 00 68 00 0C 00 | ?uint8_t[60] | ..:.h... | WARN: nothing refers to this section. + +0x0010 | 07 00 00 00 08 00 10 00 | | ........ + +0x0018 | 14 00 30 00 34 00 09 00 | | ..0.4... + +0x0020 | 38 00 3C 00 40 00 44 00 | | 8.<.@.D. + +0x0028 | 00 00 00 00 48 00 4C 00 | | ....H.L. + +0x0030 | 50 00 54 00 58 00 0A 00 | | P.T.X... + +0x0038 | 5C 00 0B 00 60 00 00 00 | | \...`... + +0x0040 | 00 00 64 00 | | ..d. + +root_table (AnnotatedBinary.Foo): + +0x0044 | FF FF 00 00 | SOffset32 | 0x0000FFFF (65535) Loc: +0xFFFFFFFFFFFF0045 | ERROR: offset to vtable. Invalid offset, points to outside the binary. + +unknown (no known references): + +0x0048 | 00 00 00 01 02 02 01 01 | ?uint8_t[600] | ........ | WARN: nothing refers to this section. + +0x0050 | D2 04 00 00 28 02 00 00 | | ....(... + +0x0058 | 01 00 00 00 02 00 00 00 | | ........ + +0x0060 | 0C 00 00 00 0A 00 00 00 | | ........ + +0x0068 | 0C 00 00 00 14 00 00 00 | | ........ + +0x0070 | 01 02 03 00 C8 01 00 00 | | ........ + +0x0078 | 5C 01 00 00 50 01 00 00 | | \...P... + +0x0080 | 34 01 00 00 24 01 00 00 | | 4...$... + +0x0088 | 14 01 00 00 0D 00 00 00 | | ........ + +0x0090 | DC 00 00 00 A0 00 00 00 | | ........ + +0x0098 | 94 00 00 00 38 00 00 00 | | ....8... + +0x00A0 | 33 00 00 00 1C 00 00 00 | | 3....... + +0x00A8 | 04 00 00 00 05 00 00 00 | | ........ + +0x00B0 | 61 6C 69 63 65 00 00 00 | | alice... + +0x00B8 | 08 00 13 00 08 00 04 00 | | ........ + +0x00C0 | 08 00 00 00 00 80 23 44 | | ......#D + +0x00C8 | 00 00 00 00 00 10 74 40 | | ......t@ + +0x00D0 | 00 00 00 05 03 00 00 00 | | ........ + +0x00D8 | 34 00 00 00 2C 00 00 00 | | 4...,... + +0x00E0 | 04 00 00 00 D2 FE FF FF | | ........ + +0x00E8 | 00 80 23 44 10 00 00 00 | | ..#D.... + +0x00F0 | 00 00 00 00 00 D8 8E 40 | | .......@ + +0x00F8 | 00 00 00 00 6A FE FF FF | | ....j... + +0x0100 | 00 00 00 03 04 00 04 00 | | ........ + +0x0108 | 04 00 00 00 FA FE FF FF | | ........ + +0x0110 | 00 00 E4 43 10 00 00 00 | | ...C.... + +0x0118 | 00 00 00 00 00 C0 5E 40 | | ......^@ + +0x0120 | 00 00 00 00 92 FE FF FF | | ........ + +0x0128 | 00 00 00 01 03 00 00 00 | | ........ + +0x0130 | 01 02 01 00 03 00 00 00 | | ........ + +0x0138 | 33 33 33 33 33 A3 45 40 | | 33333.E@ + +0x0140 | 7E 57 04 FF 5B 87 53 C0 | | ~W..[.S. + +0x0148 | 8D F0 F6 20 04 B6 42 40 | | ... ..B@ + +0x0150 | 9F 77 63 41 61 85 5E C0 | | .wcAa.^. + +0x0158 | 8F 35 23 83 DC 35 4B C0 | | .5#..5K. + +0x0160 | F6 97 DD 93 87 C5 0A 40 | | .......@ + +0x0168 | 00 00 00 00 03 00 00 00 | | ........ + +0x0170 | 20 00 00 00 14 00 00 00 | | ....... + +0x0178 | 04 00 00 00 07 00 00 00 | | ........ + +0x0180 | 63 68 61 72 6C 69 65 00 | | charlie. + +0x0188 | 03 00 00 00 62 6F 62 00 | | ....bob. + +0x0190 | 05 00 00 00 61 6C 69 63 | | ....alic + +0x0198 | 65 00 00 00 07 00 00 00 | | e....... + +0x01A0 | 63 68 61 72 6C 69 65 00 | | charlie. + +0x01A8 | 07 00 00 00 63 68 61 72 | | ....char + +0x01B0 | 6C 69 65 00 09 00 00 00 | | lie..... + +0x01B8 | 09 00 08 00 07 00 01 00 | | ........ + +0x01C0 | 02 00 03 00 06 00 05 00 | | ........ + +0x01C8 | 04 00 00 00 3A FF FF FF | | ....:... + +0x01D0 | 00 00 00 03 02 00 00 00 | | ........ + +0x01D8 | 44 00 00 00 10 00 00 00 | | D....... + +0x01E0 | 00 00 0A 00 1A 00 0C 00 | | ........ + +0x01E8 | 04 00 08 00 0A 00 00 00 | | ........ + +0x01F0 | 00 80 23 44 18 00 00 00 | | ..#D.... + +0x01F8 | 00 00 00 00 00 D8 8E 40 | | .......@ + +0x0200 | 00 00 00 00 00 00 06 00 | | ........ + +0x0208 | 06 00 05 00 06 00 00 00 | | ........ + +0x0210 | 00 03 0A 00 18 00 0C 00 | | ........ + +0x0218 | 04 00 08 00 0A 00 00 00 | | ........ + +0x0220 | 00 00 E4 43 10 00 00 00 | | ...C.... + +0x0228 | 00 00 00 00 00 C0 5E 40 | | ......^@ + +0x0230 | 00 00 00 00 A2 FF FF FF | | ........ + +0x0238 | 00 00 00 01 2F 00 00 00 | | ..../... + +0x0240 | 54 68 69 73 20 69 73 20 | | This is + +0x0248 | 61 20 6C 6F 6E 67 20 73 | | a long s + +0x0250 | 74 72 69 6E 67 20 74 6F | | tring to + +0x0258 | 20 73 68 6F 77 20 68 6F | | show ho + +0x0260 | 77 20 69 74 20 62 72 65 | | w it bre + +0x0268 | 61 6B 73 20 75 70 2E 00 | | aks up.. + +0x0270 | 00 00 0A 00 16 00 0C 00 | | ........ + +0x0278 | 04 00 08 00 0A 00 00 00 | | ........ + +0x0280 | 65 20 71 49 14 00 00 00 | | e qI.... + +0x0288 | C9 76 BE 9F 0C 24 FE 40 | | .v...$.@ + +0x0290 | 00 00 06 00 08 00 07 00 | | ........ + +0x0298 | 06 00 00 00 00 00 00 01 | | ........ diff --git a/tests/annotated_binary/tests/invalid_root_table_vtable_offset.bin b/tests/annotated_binary/tests/invalid_root_table_vtable_offset.bin new file mode 100644 index 0000000000000000000000000000000000000000..a3075ea0d5edcfbce336bed84bba84dbcd8fb16e GIT binary patch literal 672 zcmZXR!7D^j6vn^%=3(Zcrc9b-amy?$gfdF9co;>*6h)D|8IyTThMB=mO0q(sEQ$ZY zQnOKPtt{C21FS48jPJZBjojYvoqNwc=iGa~n*cC4IXMONBZ~&qaUDb$5p*Mt5c)6x z8wq-WQA{9-8O*`L0_w5kd6!YCcoSt9N{`4QnLKM*h(C2^nL`fd0(uDoc|jZ;5PNnK?qi0zSaGh*+~nw9y(>GIM0hc<7A?8}|> zpmVTTKIv`Sf9V}Be_Xtt9o}0uQ@lJ)D>}$|qIEj!6mo9H+e_tBe|oImubzjP7h>mi zRM}u=EwiLvf5q=dbWae!4+|}P1yM@gL3D_UmGPqkSV3ykiZ5UxS{;x7dR+VGs4j-j zWZk0X=jdF1eMJ{b1(&9j*TrmpM+b4Y4m< L?joIeccI+hZO&{e literal 0 HcmV?d00001 diff --git a/tests/annotated_binary/tests/invalid_string_length.afb b/tests/annotated_binary/tests/invalid_string_length.afb new file mode 100644 index 000000000..dff5cf158 --- /dev/null +++ b/tests/annotated_binary/tests/invalid_string_length.afb @@ -0,0 +1,295 @@ +// Annotated Flatbuffer Binary +// +// Schema file: annotated_binary.fbs +// Binary file: tests/invalid_string_length.bin + +header: + +0x0000 | 44 00 00 00 | UOffset32 | 0x00000044 (68) Loc: +0x0044 | offset to root table `AnnotatedBinary.Foo` + +0x0004 | 41 4E 4E 4F | char[4] | ANNO | File Identifier + +padding: + +0x0008 | 00 00 | uint8_t[2] | .. | padding + +vtable (AnnotatedBinary.Foo): + +0x000A | 3A 00 | uint16_t | 0x003A (58) | size of this vtable + +0x000C | 68 00 | uint16_t | 0x0068 (104) | size of referring table + +0x000E | 0C 00 | VOffset16 | 0x000C (12) | offset to field `counter` (id: 0) + +0x0010 | 07 00 | VOffset16 | 0x0007 (7) | offset to field `healthy` (id: 1) + +0x0012 | 00 00 | VOffset16 | 0x0000 (0) | offset to field `level` (id: 2) (Long) + +0x0014 | 08 00 | VOffset16 | 0x0008 (8) | offset to field `meal` (id: 3) + +0x0016 | 10 00 | VOffset16 | 0x0010 (16) | offset to field `bar` (id: 4) + +0x0018 | 14 00 | VOffset16 | 0x0014 (20) | offset to field `home` (id: 5) + +0x001A | 30 00 | VOffset16 | 0x0030 (48) | offset to field `name` (id: 6) + +0x001C | 34 00 | VOffset16 | 0x0034 (52) | offset to field `bars` (id: 7) + +0x001E | 09 00 | VOffset16 | 0x0009 (9) | offset to field `bar_baz_type` (id: 8) + +0x0020 | 38 00 | VOffset16 | 0x0038 (56) | offset to field `bar_baz` (id: 9) + +0x0022 | 3C 00 | VOffset16 | 0x003C (60) | offset to field `accounts` (id: 10) + +0x0024 | 40 00 | VOffset16 | 0x0040 (64) | offset to field `bob` (id: 11) + +0x0026 | 44 00 | VOffset16 | 0x0044 (68) | offset to field `alice` (id: 12) + +0x0028 | 00 00 | VOffset16 | 0x0000 (0) | offset to field `maybe_i32` (id: 13) (Int) + +0x002A | 00 00 | VOffset16 | 0x0000 (0) | offset to field `default_i32` (id: 14) (Int) + +0x002C | 48 00 | VOffset16 | 0x0048 (72) | offset to field `just_i32` (id: 15) + +0x002E | 4C 00 | VOffset16 | 0x004C (76) | offset to field `names` (id: 16) + +0x0030 | 50 00 | VOffset16 | 0x0050 (80) | offset to field `points_of_interest` (id: 17) + +0x0032 | 54 00 | VOffset16 | 0x0054 (84) | offset to field `foobars_type` (id: 18) + +0x0034 | 58 00 | VOffset16 | 0x0058 (88) | offset to field `foobars` (id: 19) + +0x0036 | 0A 00 | VOffset16 | 0x000A (10) | offset to field `measurement_type` (id: 20) + +0x0038 | 5C 00 | VOffset16 | 0x005C (92) | offset to field `measurement` (id: 21) + +0x003A | 0B 00 | VOffset16 | 0x000B (11) | offset to field `anything_type` (id: 22) + +0x003C | 60 00 | VOffset16 | 0x0060 (96) | offset to field `anything` (id: 23) + +0x003E | 00 00 | VOffset16 | 0x0000 (0) | offset to field `temperature` (id: 24) (Float) + +0x0040 | 00 00 | VOffset16 | 0x0000 (0) | offset to field `teetotaler` (id: 25) (Obj) + +0x0042 | 64 00 | VOffset16 | 0x0064 (100) | offset to field `charlie` (id: 26) + +root_table (AnnotatedBinary.Foo): + +0x0044 | 3A 00 00 00 | SOffset32 | 0x0000003A (58) Loc: +0x000A | offset to vtable + +0x0048 | 00 00 00 | uint8_t[3] | ... | padding + +0x004B | 01 | uint8_t | 0x01 (1) | table field `healthy` (Bool) + +0x004C | 02 | uint8_t | 0x02 (2) | table field `meal` (Byte) + +0x004D | 02 | UType8 | 0x02 (2) | table field `bar_baz_type` (UType) + +0x004E | 01 | UType8 | 0x01 (1) | table field `measurement_type` (UType) + +0x004F | 01 | UType8 | 0x01 (1) | table field `anything_type` (UType) + +0x0050 | D2 04 00 00 | uint32_t | 0x000004D2 (1234) | table field `counter` (Int) + +0x0054 | 28 02 00 00 | UOffset32 | 0x00000228 (552) Loc: +0x027C | offset to field `bar` (table) + +0x0058 | 01 00 00 00 | uint32_t | 0x00000001 (1) | struct field `AnnotatedBinary.Building.floors` (Int) + +0x005C | 02 00 00 00 | uint32_t | 0x00000002 (2) | struct field `AnnotatedBinary.Building.doors` (Int) + +0x0060 | 0C 00 00 00 | uint32_t | 0x0000000C (12) | struct field `AnnotatedBinary.Building.windows` (Int) + +0x0064 | 0A 00 00 00 | uint32_t | 0x0000000A (10) | array field `AnnotatedBinary.Dimension.values[0]` (Int) + +0x0068 | 0C 00 00 00 | uint32_t | 0x0000000C (12) | array field `AnnotatedBinary.Dimension.values[1]` (Int) + +0x006C | 14 00 00 00 | uint32_t | 0x00000014 (20) | array field `AnnotatedBinary.Dimension.values[2]` (Int) + +0x0070 | 01 | uint8_t | 0x01 (1) | struct field `AnnotatedBinary.Tolerance.width` (UByte) + +0x0071 | 02 | uint8_t | 0x02 (2) | struct field `AnnotatedBinary.Tolerance.width` (UByte) + +0x0072 | 03 | uint8_t | 0x03 (3) | struct field `AnnotatedBinary.Tolerance.width` (UByte) + +0x0073 | 00 | uint8_t[1] | . | padding + +0x0074 | C8 01 00 00 | UOffset32 | 0x000001C8 (456) Loc: +0x023C | offset to field `name` (string) + +0x0078 | 5C 01 00 00 | UOffset32 | 0x0000015C (348) Loc: +0x01D4 | offset to field `bars` (vector) + +0x007C | 50 01 00 00 | UOffset32 | 0x00000150 (336) Loc: +0x01CC | offset to field `bar_baz` (union of type `Baz`) + +0x0080 | 34 01 00 00 | UOffset32 | 0x00000134 (308) Loc: +0x01B4 | offset to field `accounts` (vector) + +0x0084 | 24 01 00 00 | UOffset32 | 0x00000124 (292) Loc: +0x01A8 | offset to field `bob` (string) + +0x0088 | 14 01 00 00 | UOffset32 | 0x00000114 (276) Loc: +0x019C | offset to field `alice` (string) + +0x008C | 0D 00 00 00 | uint32_t | 0x0000000D (13) | table field `just_i32` (Int) + +0x0090 | DC 00 00 00 | UOffset32 | 0x000000DC (220) Loc: +0x016C | offset to field `names` (vector) + +0x0094 | A0 00 00 00 | UOffset32 | 0x000000A0 (160) Loc: +0x0134 | offset to field `points_of_interest` (vector) + +0x0098 | 94 00 00 00 | UOffset32 | 0x00000094 (148) Loc: +0x012C | offset to field `foobars_type` (vector) + +0x009C | 38 00 00 00 | UOffset32 | 0x00000038 (56) Loc: +0x00D4 | offset to field `foobars` (vector) + +0x00A0 | 33 00 00 00 | UOffset32 | 0x00000033 (51) Loc: +0x00D3 | offset to field `measurement` (union of type `Tolerance`) + +0x00A4 | 1C 00 00 00 | UOffset32 | 0x0000001C (28) Loc: +0x00C0 | offset to field `anything` (union of type `Bar`) + +0x00A8 | 04 00 00 00 | UOffset32 | 0x00000004 (4) Loc: +0x00AC | offset to field `charlie` (string) + +string (AnnotatedBinary.Foo.charlie): + +0x00AC | FF FF 00 00 | uint32_t | 0x0000FFFF (65535) | ERROR: length of string. Length is longer than the binary. + +unknown (no known references): + +0x00B0 | 61 6C 69 63 65 00 00 00 | ?uint8_t[8] | alice... | WARN: nothing refers to this section. + +vtable (AnnotatedBinary.Bar): + +0x00B8 | 08 00 | uint16_t | 0x0008 (8) | size of this vtable + +0x00BA | 13 00 | uint16_t | 0x0013 (19) | size of referring table + +0x00BC | 08 00 | VOffset16 | 0x0008 (8) | offset to field `a` (id: 0) + +0x00BE | 04 00 | VOffset16 | 0x0004 (4) | offset to field `b` (id: 1) + +table (AnnotatedBinary.Bar): + +0x00C0 | 08 00 00 00 | SOffset32 | 0x00000008 (8) Loc: +0x00B8 | offset to vtable + +0x00C4 | 00 80 23 44 | float | 0x44238000 (654.000000) | table field `b` (Float) + +0x00C8 | 00 00 00 00 00 10 74 40 | double | 0x4074100000000000 (321.000000) | table field `a` (Double) + +0x00D0 | 00 00 00 | uint8_t[3] | ... | padding + +union (AnnotatedBinary.Tolerance.measurement): + +0x00D3 | 05 | uint8_t | 0x05 (5) | struct field `AnnotatedBinary.Tolerance.width` (UByte) + +vector (AnnotatedBinary.Foo.foobars): + +0x00D4 | 03 00 00 00 | uint32_t | 0x00000003 (3) | length of vector (# items) + +0x00D8 | 34 00 00 00 | UOffset32 | 0x00000034 (52) Loc: +0x010C | offset to union[0] (`Bar`) + +0x00DC | 2C 00 00 00 | UOffset32 | 0x0000002C (44) Loc: +0x0108 | offset to union[1] (`Baz`) + +0x00E0 | 04 00 00 00 | UOffset32 | 0x00000004 (4) Loc: +0x00E4 | offset to union[2] (`Bar`) + +table (AnnotatedBinary.Bar): + +0x00E4 | D2 FE FF FF | SOffset32 | 0xFFFFFED2 (-302) Loc: +0x0212 | offset to vtable + +0x00E8 | 00 80 23 44 | float | 0x44238000 (654.000000) | table field `b` (Float) + +0x00EC | 10 00 00 00 | UOffset32 | 0x00000010 (16) Loc: +0x00FC | offset to field `c` (table) + +0x00F0 | 00 00 00 00 00 D8 8E 40 | double | 0x408ED80000000000 (987.000000) | table field `a` (Double) + +0x00F8 | 00 00 00 00 | uint8_t[4] | .... | padding + +table (AnnotatedBinary.Baz): + +0x00FC | 6A FE FF FF | SOffset32 | 0xFFFFFE6A (-406) Loc: +0x0292 | offset to vtable + +0x0100 | 00 00 00 | uint8_t[3] | ... | padding + +0x0103 | 03 | uint8_t | 0x03 (3) | table field `meal` (Byte) + +vtable (AnnotatedBinary.Baz): + +0x0104 | 04 00 | uint16_t | 0x0004 (4) | size of this vtable + +0x0106 | 04 00 | uint16_t | 0x0004 (4) | size of referring table + +table (AnnotatedBinary.Baz): + +0x0108 | 04 00 00 00 | SOffset32 | 0x00000004 (4) Loc: +0x0104 | offset to vtable + +table (AnnotatedBinary.Bar): + +0x010C | FA FE FF FF | SOffset32 | 0xFFFFFEFA (-262) Loc: +0x0212 | offset to vtable + +0x0110 | 00 00 E4 43 | float | 0x43E40000 (456.000000) | table field `b` (Float) + +0x0114 | 10 00 00 00 | UOffset32 | 0x00000010 (16) Loc: +0x0124 | offset to field `c` (table) + +0x0118 | 00 00 00 00 00 C0 5E 40 | double | 0x405EC00000000000 (123.000000) | table field `a` (Double) + +0x0120 | 00 00 00 00 | uint8_t[4] | .... | padding + +table (AnnotatedBinary.Baz): + +0x0124 | 92 FE FF FF | SOffset32 | 0xFFFFFE92 (-366) Loc: +0x0292 | offset to vtable + +0x0128 | 00 00 00 | uint8_t[3] | ... | padding + +0x012B | 01 | uint8_t | 0x01 (1) | table field `meal` (Byte) + +vector (AnnotatedBinary.Foo.foobars_type): + +0x012C | 03 00 00 00 | uint32_t | 0x00000003 (3) | length of vector (# items) + +0x0130 | 01 | UType8 | 0x01 (1) | value[0] + +0x0131 | 02 | UType8 | 0x02 (2) | value[1] + +0x0132 | 01 | UType8 | 0x01 (1) | value[2] + +vector (AnnotatedBinary.Foo.points_of_interest): + +0x0134 | 03 00 00 00 | uint32_t | 0x00000003 (3) | length of vector (# items) + +0x0138 | 33 33 33 33 33 A3 45 40 | double | 0x4045A33333333333 (43.275000) | struct field `AnnotatedBinary.Location.latitude` (Double) + +0x0140 | 7E 57 04 FF 5B 87 53 C0 | double | 0xC053875BFF04577E (-78.114990) | struct field `AnnotatedBinary.Location.longitude` (Double) + +0x0148 | 8D F0 F6 20 04 B6 42 40 | double | 0x4042B60420F6F08D (37.422001) | struct field `AnnotatedBinary.Location.latitude` (Double) + +0x0150 | 9F 77 63 41 61 85 5E C0 | double | 0xC05E85614163779F (-122.084061) | struct field `AnnotatedBinary.Location.longitude` (Double) + +0x0158 | 8F 35 23 83 DC 35 4B C0 | double | 0xC04B35DC8323358F (-54.420792) | struct field `AnnotatedBinary.Location.latitude` (Double) + +0x0160 | F6 97 DD 93 87 C5 0A 40 | double | 0x400AC58793DD97F6 (3.346450) | struct field `AnnotatedBinary.Location.longitude` (Double) + +padding: + +0x0168 | 00 00 00 00 | uint8_t[4] | .... | padding + +vector (AnnotatedBinary.Foo.names): + +0x016C | 03 00 00 00 | uint32_t | 0x00000003 (3) | length of vector (# items) + +0x0170 | 20 00 00 00 | UOffset32 | 0x00000020 (32) Loc: +0x0190 | offset to string[0] + +0x0174 | 14 00 00 00 | UOffset32 | 0x00000014 (20) Loc: +0x0188 | offset to string[1] + +0x0178 | 04 00 00 00 | UOffset32 | 0x00000004 (4) Loc: +0x017C | offset to string[2] + +string (AnnotatedBinary.Foo.names): + +0x017C | 07 00 00 00 | uint32_t | 0x00000007 (7) | length of string + +0x0180 | 63 68 61 72 6C 69 65 | char[7] | charlie + +0x0187 | 00 | char | 0x00 (0) | string terminator + +string (AnnotatedBinary.Foo.names): + +0x0188 | 03 00 00 00 | uint32_t | 0x00000003 (3) | length of string + +0x018C | 62 6F 62 | char[3] | bob + +0x018F | 00 | char | 0x00 (0) | string terminator + +string (AnnotatedBinary.Foo.names): + +0x0190 | 05 00 00 00 | uint32_t | 0x00000005 (5) | length of string + +0x0194 | 61 6C 69 63 65 | char[5] | alice + +0x0199 | 00 | char | 0x00 (0) | string terminator + +padding: + +0x019A | 00 00 | uint8_t[2] | .. | padding + +string (AnnotatedBinary.Foo.alice): + +0x019C | 07 00 00 00 | uint32_t | 0x00000007 (7) | length of string + +0x01A0 | 63 68 61 72 6C 69 65 | char[7] | charlie + +0x01A7 | 00 | char | 0x00 (0) | string terminator + +string (AnnotatedBinary.Foo.bob): + +0x01A8 | 07 00 00 00 | uint32_t | 0x00000007 (7) | length of string + +0x01AC | 63 68 61 72 6C 69 65 | char[7] | charlie + +0x01B3 | 00 | char | 0x00 (0) | string terminator + +vector (AnnotatedBinary.Foo.accounts): + +0x01B4 | 09 00 00 00 | uint32_t | 0x00000009 (9) | length of vector (# items) + +0x01B8 | 09 00 | uint16_t | 0x0009 (9) | value[0] + +0x01BA | 08 00 | uint16_t | 0x0008 (8) | value[1] + +0x01BC | 07 00 | uint16_t | 0x0007 (7) | value[2] + +0x01BE | 01 00 | uint16_t | 0x0001 (1) | value[3] + +0x01C0 | 02 00 | uint16_t | 0x0002 (2) | value[4] + +0x01C2 | 03 00 | uint16_t | 0x0003 (3) | value[5] + +0x01C4 | 06 00 | uint16_t | 0x0006 (6) | value[6] + +0x01C6 | 05 00 | uint16_t | 0x0005 (5) | value[7] + +0x01C8 | 04 00 | uint16_t | 0x0004 (4) | value[8] + +padding: + +0x01CA | 00 00 | uint8_t[2] | .. | padding + +table (AnnotatedBinary.Baz): + +0x01CC | 3A FF FF FF | SOffset32 | 0xFFFFFF3A (-198) Loc: +0x0292 | offset to vtable + +0x01D0 | 00 00 00 | uint8_t[3] | ... | padding + +0x01D3 | 03 | uint8_t | 0x03 (3) | table field `meal` (Byte) + +vector (AnnotatedBinary.Foo.bars): + +0x01D4 | 02 00 00 00 | uint32_t | 0x00000002 (2) | length of vector (# items) + +0x01D8 | 44 00 00 00 | UOffset32 | 0x00000044 (68) Loc: +0x021C | offset to table[0] + +0x01DC | 10 00 00 00 | UOffset32 | 0x00000010 (16) Loc: +0x01EC | offset to table[1] + +padding: + +0x01E0 | 00 00 | uint8_t[2] | .. | padding + +vtable (AnnotatedBinary.Bar): + +0x01E2 | 0A 00 | uint16_t | 0x000A (10) | size of this vtable + +0x01E4 | 1A 00 | uint16_t | 0x001A (26) | size of referring table + +0x01E6 | 0C 00 | VOffset16 | 0x000C (12) | offset to field `a` (id: 0) + +0x01E8 | 04 00 | VOffset16 | 0x0004 (4) | offset to field `b` (id: 1) + +0x01EA | 08 00 | VOffset16 | 0x0008 (8) | offset to field `c` (id: 2) + +table (AnnotatedBinary.Bar): + +0x01EC | 0A 00 00 00 | SOffset32 | 0x0000000A (10) Loc: +0x01E2 | offset to vtable + +0x01F0 | 00 80 23 44 | float | 0x44238000 (654.000000) | table field `b` (Float) + +0x01F4 | 18 00 00 00 | UOffset32 | 0x00000018 (24) Loc: +0x020C | offset to field `c` (table) + +0x01F8 | 00 00 00 00 00 D8 8E 40 | double | 0x408ED80000000000 (987.000000) | table field `a` (Double) + +0x0200 | 00 00 00 00 00 00 | uint8_t[6] | ...... | padding + +vtable (AnnotatedBinary.Baz): + +0x0206 | 06 00 | uint16_t | 0x0006 (6) | size of this vtable + +0x0208 | 06 00 | uint16_t | 0x0006 (6) | size of referring table + +0x020A | 05 00 | VOffset16 | 0x0005 (5) | offset to field `meal` (id: 0) + +table (AnnotatedBinary.Baz): + +0x020C | 06 00 00 00 | SOffset32 | 0x00000006 (6) Loc: +0x0206 | offset to vtable + +0x0210 | 00 | uint8_t[1] | . | padding + +0x0211 | 03 | uint8_t | 0x03 (3) | table field `meal` (Byte) + +vtable (AnnotatedBinary.Bar): + +0x0212 | 0A 00 | uint16_t | 0x000A (10) | size of this vtable + +0x0214 | 18 00 | uint16_t | 0x0018 (24) | size of referring table + +0x0216 | 0C 00 | VOffset16 | 0x000C (12) | offset to field `a` (id: 0) + +0x0218 | 04 00 | VOffset16 | 0x0004 (4) | offset to field `b` (id: 1) + +0x021A | 08 00 | VOffset16 | 0x0008 (8) | offset to field `c` (id: 2) + +table (AnnotatedBinary.Bar): + +0x021C | 0A 00 00 00 | SOffset32 | 0x0000000A (10) Loc: +0x0212 | offset to vtable + +0x0220 | 00 00 E4 43 | float | 0x43E40000 (456.000000) | table field `b` (Float) + +0x0224 | 10 00 00 00 | UOffset32 | 0x00000010 (16) Loc: +0x0234 | offset to field `c` (table) + +0x0228 | 00 00 00 00 00 C0 5E 40 | double | 0x405EC00000000000 (123.000000) | table field `a` (Double) + +0x0230 | 00 00 00 00 | uint8_t[4] | .... | padding + +table (AnnotatedBinary.Baz): + +0x0234 | A2 FF FF FF | SOffset32 | 0xFFFFFFA2 (-94) Loc: +0x0292 | offset to vtable + +0x0238 | 00 00 00 | uint8_t[3] | ... | padding + +0x023B | 01 | uint8_t | 0x01 (1) | table field `meal` (Byte) + +string (AnnotatedBinary.Foo.name): + +0x023C | 2F 00 00 00 | uint32_t | 0x0000002F (47) | length of string + +0x0240 | 54 68 69 73 20 69 73 20 | char[47] | This is + +0x0248 | 61 20 6C 6F 6E 67 20 73 | | a long s + +0x0250 | 74 72 69 6E 67 20 74 6F | | tring to + +0x0258 | 20 73 68 6F 77 20 68 6F | | show ho + +0x0260 | 77 20 69 74 20 62 72 65 | | w it bre + +0x0268 | 61 6B 73 20 75 70 2E | | aks up. + +0x026F | 00 | char | 0x00 (0) | string terminator + +padding: + +0x0270 | 00 00 | uint8_t[2] | .. | padding + +vtable (AnnotatedBinary.Bar): + +0x0272 | 0A 00 | uint16_t | 0x000A (10) | size of this vtable + +0x0274 | 16 00 | uint16_t | 0x0016 (22) | size of referring table + +0x0276 | 0C 00 | VOffset16 | 0x000C (12) | offset to field `a` (id: 0) + +0x0278 | 04 00 | VOffset16 | 0x0004 (4) | offset to field `b` (id: 1) + +0x027A | 08 00 | VOffset16 | 0x0008 (8) | offset to field `c` (id: 2) + +table (AnnotatedBinary.Bar): + +0x027C | 0A 00 00 00 | SOffset32 | 0x0000000A (10) Loc: +0x0272 | offset to vtable + +0x0280 | 65 20 71 49 | float | 0x49712065 (987654.312500) | table field `b` (Float) + +0x0284 | 14 00 00 00 | UOffset32 | 0x00000014 (20) Loc: +0x0298 | offset to field `c` (table) + +0x0288 | C9 76 BE 9F 0C 24 FE 40 | double | 0x40FE240C9FBE76C9 (123456.789000) | table field `a` (Double) + +0x0290 | 00 00 | uint8_t[2] | .. | padding + +vtable (AnnotatedBinary.Baz): + +0x0292 | 06 00 | uint16_t | 0x0006 (6) | size of this vtable + +0x0294 | 08 00 | uint16_t | 0x0008 (8) | size of referring table + +0x0296 | 07 00 | VOffset16 | 0x0007 (7) | offset to field `meal` (id: 0) + +table (AnnotatedBinary.Baz): + +0x0298 | 06 00 00 00 | SOffset32 | 0x00000006 (6) Loc: +0x0292 | offset to vtable + +0x029C | 00 00 00 | uint8_t[3] | ... | padding + +0x029F | 01 | uint8_t | 0x01 (1) | table field `meal` (Byte) diff --git a/tests/annotated_binary/tests/invalid_string_length.bin b/tests/annotated_binary/tests/invalid_string_length.bin new file mode 100644 index 0000000000000000000000000000000000000000..c4ef6788a4928ede1ae2ee4cf83e3352f018e6d7 GIT binary patch literal 672 zcmZWmK`TU26#nj;hna_(GHH^sb? zW~10zS+Mg1tSl^y@4SbmoZk1&z2|)A+apZSms#nVG7P1jOrYHW6hn0E2(o=2p;tx#4@@o)Ng__fhzQZh z{0nhKoD+RS57A1nEh-hj$+_ta*FiK9CPCY4^Dh`K+1%9x_=^)Agw#EKv67rH*PcBe z+u~Ox4g^fHg!k#~--iEqvYyBU{M&L{5m4 z*HLAIm9?yre*G1H9??BP_;Xlj;VXzz@(!XyRJ_=a4qylAQ7f^4g=jS&|Mj@`&rw~Z z&t%=A=I7{Ketkt3O9hv%l-I>#e&RS7#ZFI82LUUFBjNTj*Js!93E*oNB Nw%kP~^X@{qzX2VxY+nEX literal 0 HcmV?d00001 diff --git a/tests/annotated_binary/tests/invalid_string_length_cut_short.afb b/tests/annotated_binary/tests/invalid_string_length_cut_short.afb new file mode 100644 index 000000000..27ba5b3be --- /dev/null +++ b/tests/annotated_binary/tests/invalid_string_length_cut_short.afb @@ -0,0 +1,80 @@ +// Annotated Flatbuffer Binary +// +// Schema file: annotated_binary.fbs +// Binary file: tests/invalid_string_length_cut_short.bin + +header: + +0x00 | 44 00 00 00 | UOffset32 | 0x00000044 (68) Loc: +0x44 | offset to root table `AnnotatedBinary.Foo` + +0x04 | 41 4E 4E 4F | char[4] | ANNO | File Identifier + +padding: + +0x08 | 00 00 | uint8_t[2] | .. | padding + +vtable (AnnotatedBinary.Foo): + +0x0A | 3A 00 | uint16_t | 0x003A (58) | size of this vtable + +0x0C | 68 00 | uint16_t | 0x0068 (104) | size of referring table + +0x0E | 0C 00 | VOffset16 | 0x000C (12) | offset to field `counter` (id: 0) + +0x10 | 07 00 | VOffset16 | 0x0007 (7) | offset to field `healthy` (id: 1) + +0x12 | 00 00 | VOffset16 | 0x0000 (0) | offset to field `level` (id: 2) (Long) + +0x14 | 08 00 | VOffset16 | 0x0008 (8) | offset to field `meal` (id: 3) + +0x16 | 10 00 | VOffset16 | 0x0010 (16) | offset to field `bar` (id: 4) + +0x18 | 14 00 | VOffset16 | 0x0014 (20) | offset to field `home` (id: 5) + +0x1A | 30 00 | VOffset16 | 0x0030 (48) | offset to field `name` (id: 6) + +0x1C | 34 00 | VOffset16 | 0x0034 (52) | offset to field `bars` (id: 7) + +0x1E | 09 00 | VOffset16 | 0x0009 (9) | offset to field `bar_baz_type` (id: 8) + +0x20 | 38 00 | VOffset16 | 0x0038 (56) | offset to field `bar_baz` (id: 9) + +0x22 | 3C 00 | VOffset16 | 0x003C (60) | offset to field `accounts` (id: 10) + +0x24 | 40 00 | VOffset16 | 0x0040 (64) | offset to field `bob` (id: 11) + +0x26 | 44 00 | VOffset16 | 0x0044 (68) | offset to field `alice` (id: 12) + +0x28 | 00 00 | VOffset16 | 0x0000 (0) | offset to field `maybe_i32` (id: 13) (Int) + +0x2A | 00 00 | VOffset16 | 0x0000 (0) | offset to field `default_i32` (id: 14) (Int) + +0x2C | 48 00 | VOffset16 | 0x0048 (72) | offset to field `just_i32` (id: 15) + +0x2E | 4C 00 | VOffset16 | 0x004C (76) | offset to field `names` (id: 16) + +0x30 | 50 00 | VOffset16 | 0x0050 (80) | offset to field `points_of_interest` (id: 17) + +0x32 | 54 00 | VOffset16 | 0x0054 (84) | offset to field `foobars_type` (id: 18) + +0x34 | 58 00 | VOffset16 | 0x0058 (88) | offset to field `foobars` (id: 19) + +0x36 | 0A 00 | VOffset16 | 0x000A (10) | offset to field `measurement_type` (id: 20) + +0x38 | 5C 00 | VOffset16 | 0x005C (92) | offset to field `measurement` (id: 21) + +0x3A | 0B 00 | VOffset16 | 0x000B (11) | offset to field `anything_type` (id: 22) + +0x3C | 60 00 | VOffset16 | 0x0060 (96) | offset to field `anything` (id: 23) + +0x3E | 00 00 | VOffset16 | 0x0000 (0) | offset to field `temperature` (id: 24) (Float) + +0x40 | 00 00 | VOffset16 | 0x0000 (0) | offset to field `teetotaler` (id: 25) (Obj) + +0x42 | 64 00 | VOffset16 | 0x0064 (100) | offset to field `charlie` (id: 26) + +root_table (AnnotatedBinary.Foo): + +0x44 | 3A 00 00 00 | SOffset32 | 0x0000003A (58) Loc: +0x0A | offset to vtable + +0x48 | 00 00 00 | uint8_t[3] | ... | padding + +0x4B | 01 | uint8_t | 0x01 (1) | table field `healthy` (Bool) + +0x4C | 02 | uint8_t | 0x02 (2) | table field `meal` (Byte) + +0x4D | 02 | UType8 | 0x02 (2) | table field `bar_baz_type` (UType) + +0x4E | 01 | UType8 | 0x01 (1) | table field `measurement_type` (UType) + +0x4F | 01 | UType8 | 0x01 (1) | table field `anything_type` (UType) + +0x50 | D2 04 00 00 | uint32_t | 0x000004D2 (1234) | table field `counter` (Int) + +0x54 | 28 02 00 00 | UOffset32 | 0x00000228 (552) Loc: +0x27C | ERROR: offset to field `bar`. Location is outside the binary. + +0x58 | 01 00 00 00 | uint32_t | 0x00000001 (1) | struct field `AnnotatedBinary.Building.floors` (Int) + +0x5C | 02 00 00 00 | uint32_t | 0x00000002 (2) | struct field `AnnotatedBinary.Building.doors` (Int) + +0x60 | 0C 00 00 00 | uint32_t | 0x0000000C (12) | struct field `AnnotatedBinary.Building.windows` (Int) + +0x64 | 0A 00 00 00 | uint32_t | 0x0000000A (10) | array field `AnnotatedBinary.Dimension.values[0]` (Int) + +0x68 | 0C 00 00 00 | uint32_t | 0x0000000C (12) | array field `AnnotatedBinary.Dimension.values[1]` (Int) + +0x6C | 14 00 00 00 | uint32_t | 0x00000014 (20) | array field `AnnotatedBinary.Dimension.values[2]` (Int) + +0x70 | 01 | uint8_t | 0x01 (1) | struct field `AnnotatedBinary.Tolerance.width` (UByte) + +0x71 | 02 | uint8_t | 0x02 (2) | struct field `AnnotatedBinary.Tolerance.width` (UByte) + +0x72 | 03 | uint8_t | 0x03 (3) | struct field `AnnotatedBinary.Tolerance.width` (UByte) + +0x73 | 00 | uint8_t[1] | . | padding + +0x74 | C8 01 00 00 | UOffset32 | 0x000001C8 (456) Loc: +0x23C | ERROR: offset to field `name`. Location is outside the binary. + +0x78 | 5C 01 00 00 | UOffset32 | 0x0000015C (348) Loc: +0x1D4 | ERROR: offset to field `bars`. Location is outside the binary. + +0x7C | 50 01 00 00 | UOffset32 | 0x00000150 (336) Loc: +0x1CC | ERROR: offset to field `bar_baz`. Location is outside the binary. + +0x80 | 34 01 00 00 | UOffset32 | 0x00000134 (308) Loc: +0x1B4 | ERROR: offset to field `accounts`. Location is outside the binary. + +0x84 | 24 01 00 00 | UOffset32 | 0x00000124 (292) Loc: +0x1A8 | ERROR: offset to field `bob`. Location is outside the binary. + +0x88 | 14 01 00 00 | UOffset32 | 0x00000114 (276) Loc: +0x19C | ERROR: offset to field `alice`. Location is outside the binary. + +0x8C | 0D 00 00 00 | uint32_t | 0x0000000D (13) | table field `just_i32` (Int) + +0x90 | DC 00 00 00 | UOffset32 | 0x000000DC (220) Loc: +0x16C | ERROR: offset to field `names`. Location is outside the binary. + +0x94 | A0 00 00 00 | UOffset32 | 0x000000A0 (160) Loc: +0x134 | ERROR: offset to field `points_of_interest`. Location is outside the binary. + +0x98 | 94 00 00 00 | UOffset32 | 0x00000094 (148) Loc: +0x12C | ERROR: offset to field `foobars_type`. Location is outside the binary. + +0x9C | 38 00 00 00 | UOffset32 | 0x00000038 (56) Loc: +0xD4 | ERROR: offset to field `foobars`. Location is outside the binary. + +0xA0 | 33 00 00 00 | UOffset32 | 0x00000033 (51) Loc: +0xD3 | ERROR: offset to field `measurement`. Location is outside the binary. + +0xA4 | 1C 00 00 00 | UOffset32 | 0x0000001C (28) Loc: +0xC0 | ERROR: offset to field `anything`. Location is outside the binary. + +0xA8 | 04 00 00 00 | UOffset32 | 0x00000004 (4) Loc: +0xAC | offset to field `charlie` (string) + +string (AnnotatedBinary.Foo.charlie): + +0xAC | 05 00 | ?uint8_t[2] | .. | ERROR: length of string. Incomplete binary, expected to read 4 bytes here diff --git a/tests/annotated_binary/tests/invalid_string_length_cut_short.bin b/tests/annotated_binary/tests/invalid_string_length_cut_short.bin new file mode 100644 index 0000000000000000000000000000000000000000..69f7e11eaa22129040965af69b948cfbf66e81b5 GIT binary patch literal 174 zcmXBMEe^s!6h+}P1BCwsF|ra-*@TLQARwtgkWzs_R3H#6hy}15G@8Y5QYQIwGxyEB z8aOn~8MZuFF!nxSMWUc&O2v*nwJjVu(Q@I+jE*_CzPwT$=y!C4HC literal 0 HcmV?d00001 diff --git a/tests/annotated_binary/tests/invalid_struct_array_field_cut_short.afb b/tests/annotated_binary/tests/invalid_struct_array_field_cut_short.afb new file mode 100644 index 000000000..73726fa20 --- /dev/null +++ b/tests/annotated_binary/tests/invalid_struct_array_field_cut_short.afb @@ -0,0 +1,72 @@ +// Annotated Flatbuffer Binary +// +// Schema file: annotated_binary.fbs +// Binary file: tests/invalid_struct_array_field_cut_short.bin + +header: + +0x00 | 44 00 00 00 | UOffset32 | 0x00000044 (68) Loc: +0x44 | offset to root table `AnnotatedBinary.Foo` + +0x04 | 41 4E 4E 4F | char[4] | ANNO | File Identifier + +padding: + +0x08 | 00 00 | uint8_t[2] | .. | padding + +vtable (AnnotatedBinary.Foo): + +0x0A | 3A 00 | uint16_t | 0x003A (58) | size of this vtable + +0x0C | 68 00 | uint16_t | 0x0068 (104) | ERROR: size of referring table. Size of table is larger than the binary. + +0x0E | 0C 00 | VOffset16 | 0x000C (12) | offset to field `counter` (id: 0) + +0x10 | 07 00 | VOffset16 | 0x0007 (7) | offset to field `healthy` (id: 1) + +0x12 | 00 00 | VOffset16 | 0x0000 (0) | offset to field `level` (id: 2) (Long) + +0x14 | 08 00 | VOffset16 | 0x0008 (8) | offset to field `meal` (id: 3) + +0x16 | 10 00 | VOffset16 | 0x0010 (16) | offset to field `bar` (id: 4) + +0x18 | 14 00 | VOffset16 | 0x0014 (20) | offset to field `home` (id: 5) + +0x1A | 30 00 | VOffset16 | 0x0030 (48) | ERROR: offset to field `name` (id: 6). Invalid offset, points to outside the binary. + +0x1C | 34 00 | VOffset16 | 0x0034 (52) | ERROR: offset to field `bars` (id: 7). Invalid offset, points to outside the binary. + +0x1E | 09 00 | VOffset16 | 0x0009 (9) | offset to field `bar_baz_type` (id: 8) + +0x20 | 38 00 | VOffset16 | 0x0038 (56) | ERROR: offset to field `bar_baz` (id: 9). Invalid offset, points to outside the binary. + +0x22 | 3C 00 | VOffset16 | 0x003C (60) | ERROR: offset to field `accounts` (id: 10). Invalid offset, points to outside the binary. + +0x24 | 40 00 | VOffset16 | 0x0040 (64) | ERROR: offset to field `bob` (id: 11). Invalid offset, points to outside the binary. + +0x26 | 44 00 | VOffset16 | 0x0044 (68) | ERROR: offset to field `alice` (id: 12). Invalid offset, points to outside the binary. + +0x28 | 00 00 | VOffset16 | 0x0000 (0) | offset to field `maybe_i32` (id: 13) (Int) + +0x2A | 00 00 | VOffset16 | 0x0000 (0) | offset to field `default_i32` (id: 14) (Int) + +0x2C | 48 00 | VOffset16 | 0x0048 (72) | ERROR: offset to field `just_i32` (id: 15). Invalid offset, points to outside the binary. + +0x2E | 4C 00 | VOffset16 | 0x004C (76) | ERROR: offset to field `names` (id: 16). Invalid offset, points to outside the binary. + +0x30 | 50 00 | VOffset16 | 0x0050 (80) | ERROR: offset to field `points_of_interest` (id: 17). Invalid offset, points to outside the binary. + +0x32 | 54 00 | VOffset16 | 0x0054 (84) | ERROR: offset to field `foobars_type` (id: 18). Invalid offset, points to outside the binary. + +0x34 | 58 00 | VOffset16 | 0x0058 (88) | ERROR: offset to field `foobars` (id: 19). Invalid offset, points to outside the binary. + +0x36 | 0A 00 | VOffset16 | 0x000A (10) | offset to field `measurement_type` (id: 20) + +0x38 | 5C 00 | VOffset16 | 0x005C (92) | ERROR: offset to field `measurement` (id: 21). Invalid offset, points to outside the binary. + +0x3A | 0B 00 | VOffset16 | 0x000B (11) | offset to field `anything_type` (id: 22) + +0x3C | 60 00 | VOffset16 | 0x0060 (96) | ERROR: offset to field `anything` (id: 23). Invalid offset, points to outside the binary. + +0x3E | 00 00 | VOffset16 | 0x0000 (0) | offset to field `temperature` (id: 24) (Float) + +0x40 | 00 00 | VOffset16 | 0x0000 (0) | offset to field `teetotaler` (id: 25) (Obj) + +0x42 | 64 00 | VOffset16 | 0x0064 (100) | ERROR: offset to field `charlie` (id: 26). Invalid offset, points to outside the binary. + +0x28 | 00 00 | VOffset16 | 0x0000 (0) | offset to unknown field (id: 13) + +0x2A | 00 00 | VOffset16 | 0x0000 (0) | offset to unknown field (id: 14) + +0x2C | 48 00 | VOffset16 | 0x0048 (72) | offset to unknown field (id: 15) + +0x2E | 4C 00 | VOffset16 | 0x004C (76) | offset to unknown field (id: 16) + +0x30 | 50 00 | VOffset16 | 0x0050 (80) | offset to unknown field (id: 17) + +0x32 | 54 00 | VOffset16 | 0x0054 (84) | offset to unknown field (id: 18) + +0x34 | 58 00 | VOffset16 | 0x0058 (88) | offset to unknown field (id: 19) + +0x36 | 0A 00 | VOffset16 | 0x000A (10) | offset to unknown field (id: 20) + +0x38 | 5C 00 | VOffset16 | 0x005C (92) | offset to unknown field (id: 21) + +0x3A | 0B 00 | VOffset16 | 0x000B (11) | offset to unknown field (id: 22) + +0x3C | 60 00 | VOffset16 | 0x0060 (96) | offset to unknown field (id: 23) + +0x3E | 00 00 | VOffset16 | 0x0000 (0) | offset to unknown field (id: 24) + +0x40 | 00 00 | VOffset16 | 0x0000 (0) | offset to unknown field (id: 25) + +0x42 | 64 00 | VOffset16 | 0x0064 (100) | offset to unknown field (id: 26) + +root_table (AnnotatedBinary.Foo): + +0x44 | 3A 00 00 00 | SOffset32 | 0x0000003A (58) Loc: +0x0A | offset to vtable + +0x48 | 00 00 00 | uint8_t[3] | ... | padding + +0x4B | 01 | uint8_t | 0x01 (1) | table field `healthy` (Bool) + +0x4C | 02 | uint8_t | 0x02 (2) | table field `meal` (Byte) + +0x4D | 02 | UType8 | 0x02 (2) | table field `bar_baz_type` (UType) + +0x4E | 01 | UType8 | 0x01 (1) | table field `measurement_type` (UType) + +0x4F | 01 | UType8 | 0x01 (1) | table field `anything_type` (UType) + +0x50 | D2 04 00 00 | uint32_t | 0x000004D2 (1234) | table field `counter` (Int) + +0x54 | 28 02 00 00 | UOffset32 | 0x00000228 (552) Loc: +0x27C | ERROR: offset to field `bar`. Location is outside the binary. + +0x58 | 01 00 00 00 | uint32_t | 0x00000001 (1) | struct field `AnnotatedBinary.Building.floors` (Int) + +0x5C | 02 00 00 00 | uint32_t | 0x00000002 (2) | struct field `AnnotatedBinary.Building.doors` (Int) + +0x60 | 0C 00 00 00 | uint32_t | 0x0000000C (12) | struct field `AnnotatedBinary.Building.windows` (Int) + +0x64 | 0A 00 00 00 | uint32_t | 0x0000000A (10) | array field `AnnotatedBinary.Dimension.values[0]` (Int) + +0x68 | 0C 00 | ?uint8_t[2] | .. | ERROR: array field `AnnotatedBinary.Dimension.values[1]` (Int). Expected to read 4 bytes. diff --git a/tests/annotated_binary/tests/invalid_struct_array_field_cut_short.bin b/tests/annotated_binary/tests/invalid_struct_array_field_cut_short.bin new file mode 100644 index 0000000000000000000000000000000000000000..b701f73551eab7a394cdb102c114e0d4c6399fa7 GIT binary patch literal 106 zcmW;EArFFJ7{u}4`_2tS1HlhLG#H#C=teLwFc1s`gMrWMC*qMSxBKtzIy{D9I3Y`t4{kDNtBEiuT`E{&)xC literal 0 HcmV?d00001 diff --git a/tests/annotated_binary/tests/invalid_struct_field_cut_short.afb b/tests/annotated_binary/tests/invalid_struct_field_cut_short.afb new file mode 100644 index 000000000..a7ab652a9 --- /dev/null +++ b/tests/annotated_binary/tests/invalid_struct_field_cut_short.afb @@ -0,0 +1,69 @@ +// Annotated Flatbuffer Binary +// +// Schema file: annotated_binary.fbs +// Binary file: tests/invalid_struct_field_cut_short.bin + +header: + +0x00 | 44 00 00 00 | UOffset32 | 0x00000044 (68) Loc: +0x44 | offset to root table `AnnotatedBinary.Foo` + +0x04 | 41 4E 4E 4F | char[4] | ANNO | File Identifier + +padding: + +0x08 | 00 00 | uint8_t[2] | .. | padding + +vtable (AnnotatedBinary.Foo): + +0x0A | 3A 00 | uint16_t | 0x003A (58) | size of this vtable + +0x0C | 68 00 | uint16_t | 0x0068 (104) | ERROR: size of referring table. Size of table is larger than the binary. + +0x0E | 0C 00 | VOffset16 | 0x000C (12) | offset to field `counter` (id: 0) + +0x10 | 07 00 | VOffset16 | 0x0007 (7) | offset to field `healthy` (id: 1) + +0x12 | 00 00 | VOffset16 | 0x0000 (0) | offset to field `level` (id: 2) (Long) + +0x14 | 08 00 | VOffset16 | 0x0008 (8) | offset to field `meal` (id: 3) + +0x16 | 10 00 | VOffset16 | 0x0010 (16) | offset to field `bar` (id: 4) + +0x18 | 14 00 | VOffset16 | 0x0014 (20) | offset to field `home` (id: 5) + +0x1A | 30 00 | VOffset16 | 0x0030 (48) | ERROR: offset to field `name` (id: 6). Invalid offset, points to outside the binary. + +0x1C | 34 00 | VOffset16 | 0x0034 (52) | ERROR: offset to field `bars` (id: 7). Invalid offset, points to outside the binary. + +0x1E | 09 00 | VOffset16 | 0x0009 (9) | offset to field `bar_baz_type` (id: 8) + +0x20 | 38 00 | VOffset16 | 0x0038 (56) | ERROR: offset to field `bar_baz` (id: 9). Invalid offset, points to outside the binary. + +0x22 | 3C 00 | VOffset16 | 0x003C (60) | ERROR: offset to field `accounts` (id: 10). Invalid offset, points to outside the binary. + +0x24 | 40 00 | VOffset16 | 0x0040 (64) | ERROR: offset to field `bob` (id: 11). Invalid offset, points to outside the binary. + +0x26 | 44 00 | VOffset16 | 0x0044 (68) | ERROR: offset to field `alice` (id: 12). Invalid offset, points to outside the binary. + +0x28 | 00 00 | VOffset16 | 0x0000 (0) | offset to field `maybe_i32` (id: 13) (Int) + +0x2A | 00 00 | VOffset16 | 0x0000 (0) | offset to field `default_i32` (id: 14) (Int) + +0x2C | 48 00 | VOffset16 | 0x0048 (72) | ERROR: offset to field `just_i32` (id: 15). Invalid offset, points to outside the binary. + +0x2E | 4C 00 | VOffset16 | 0x004C (76) | ERROR: offset to field `names` (id: 16). Invalid offset, points to outside the binary. + +0x30 | 50 00 | VOffset16 | 0x0050 (80) | ERROR: offset to field `points_of_interest` (id: 17). Invalid offset, points to outside the binary. + +0x32 | 54 00 | VOffset16 | 0x0054 (84) | ERROR: offset to field `foobars_type` (id: 18). Invalid offset, points to outside the binary. + +0x34 | 58 00 | VOffset16 | 0x0058 (88) | ERROR: offset to field `foobars` (id: 19). Invalid offset, points to outside the binary. + +0x36 | 0A 00 | VOffset16 | 0x000A (10) | offset to field `measurement_type` (id: 20) + +0x38 | 5C 00 | VOffset16 | 0x005C (92) | ERROR: offset to field `measurement` (id: 21). Invalid offset, points to outside the binary. + +0x3A | 0B 00 | VOffset16 | 0x000B (11) | offset to field `anything_type` (id: 22) + +0x3C | 60 00 | VOffset16 | 0x0060 (96) | ERROR: offset to field `anything` (id: 23). Invalid offset, points to outside the binary. + +0x3E | 00 00 | VOffset16 | 0x0000 (0) | offset to field `temperature` (id: 24) (Float) + +0x40 | 00 00 | VOffset16 | 0x0000 (0) | offset to field `teetotaler` (id: 25) (Obj) + +0x42 | 64 00 | VOffset16 | 0x0064 (100) | ERROR: offset to field `charlie` (id: 26). Invalid offset, points to outside the binary. + +0x28 | 00 00 | VOffset16 | 0x0000 (0) | offset to unknown field (id: 13) + +0x2A | 00 00 | VOffset16 | 0x0000 (0) | offset to unknown field (id: 14) + +0x2C | 48 00 | VOffset16 | 0x0048 (72) | offset to unknown field (id: 15) + +0x2E | 4C 00 | VOffset16 | 0x004C (76) | offset to unknown field (id: 16) + +0x30 | 50 00 | VOffset16 | 0x0050 (80) | offset to unknown field (id: 17) + +0x32 | 54 00 | VOffset16 | 0x0054 (84) | offset to unknown field (id: 18) + +0x34 | 58 00 | VOffset16 | 0x0058 (88) | offset to unknown field (id: 19) + +0x36 | 0A 00 | VOffset16 | 0x000A (10) | offset to unknown field (id: 20) + +0x38 | 5C 00 | VOffset16 | 0x005C (92) | offset to unknown field (id: 21) + +0x3A | 0B 00 | VOffset16 | 0x000B (11) | offset to unknown field (id: 22) + +0x3C | 60 00 | VOffset16 | 0x0060 (96) | offset to unknown field (id: 23) + +0x3E | 00 00 | VOffset16 | 0x0000 (0) | offset to unknown field (id: 24) + +0x40 | 00 00 | VOffset16 | 0x0000 (0) | offset to unknown field (id: 25) + +0x42 | 64 00 | VOffset16 | 0x0064 (100) | offset to unknown field (id: 26) + +root_table (AnnotatedBinary.Foo): + +0x44 | 3A 00 00 00 | SOffset32 | 0x0000003A (58) Loc: +0x0A | offset to vtable + +0x48 | 00 00 00 | uint8_t[3] | ... | padding + +0x4B | 01 | uint8_t | 0x01 (1) | table field `healthy` (Bool) + +0x4C | 02 | uint8_t | 0x02 (2) | table field `meal` (Byte) + +0x4D | 02 | UType8 | 0x02 (2) | table field `bar_baz_type` (UType) + +0x4E | 01 | UType8 | 0x01 (1) | table field `measurement_type` (UType) + +0x4F | 01 | UType8 | 0x01 (1) | table field `anything_type` (UType) + +0x50 | D2 04 00 00 | uint32_t | 0x000004D2 (1234) | table field `counter` (Int) + +0x54 | 28 02 00 00 | UOffset32 | 0x00000228 (552) Loc: +0x27C | ERROR: offset to field `bar`. Location is outside the binary. + +0x58 | 01 00 00 00 | uint32_t | 0x00000001 (1) | struct field `AnnotatedBinary.Building.floors` (Int) + +0x5C | 02 00 | ?uint8_t[2] | .. | ERROR: struct field `AnnotatedBinary.Building.doors` (Int). Expected to read 4 bytes. diff --git a/tests/annotated_binary/tests/invalid_struct_field_cut_short.bin b/tests/annotated_binary/tests/invalid_struct_field_cut_short.bin new file mode 100644 index 0000000000000000000000000000000000000000..537352dbfb8f57976d0fbcdf841e0b4c5f569d08 GIT binary patch literal 94 zcmW;Dp$>vj0EOZ2-nk)2An*`I1A#FDYy^V?gMmOW73J^17{YPk9tnw}KcK7!zyJUM literal 0 HcmV?d00001 diff --git a/tests/annotated_binary/tests/invalid_table_field_offset.afb b/tests/annotated_binary/tests/invalid_table_field_offset.afb new file mode 100644 index 000000000..2b1c19988 --- /dev/null +++ b/tests/annotated_binary/tests/invalid_table_field_offset.afb @@ -0,0 +1,77 @@ +// Annotated Flatbuffer Binary +// +// Schema file: annotated_binary.fbs +// Binary file: tests/invalid_table_field_offset.bin + +header: + +0x00 | 44 00 00 00 | UOffset32 | 0x00000044 (68) Loc: +0x44 | offset to root table `AnnotatedBinary.Foo` + +0x04 | 41 4E 4E 4F | char[4] | ANNO | File Identifier + +padding: + +0x08 | 00 00 | uint8_t[2] | .. | padding + +vtable (AnnotatedBinary.Foo): + +0x0A | 3A 00 | uint16_t | 0x003A (58) | size of this vtable + +0x0C | 68 00 | uint16_t | 0x0068 (104) | ERROR: size of referring table. Size of table is larger than the binary. + +0x0E | 0C 00 | VOffset16 | 0x000C (12) | offset to field `counter` (id: 0) + +0x10 | 07 00 | VOffset16 | 0x0007 (7) | offset to field `healthy` (id: 1) + +0x12 | 00 00 | VOffset16 | 0x0000 (0) | offset to field `level` (id: 2) (Long) + +0x14 | 08 00 | VOffset16 | 0x0008 (8) | offset to field `meal` (id: 3) + +0x16 | 10 00 | VOffset16 | 0x0010 (16) | offset to field `bar` (id: 4) + +0x18 | 14 00 | VOffset16 | 0x0014 (20) | offset to field `home` (id: 5) + +0x1A | 30 00 | VOffset16 | 0x0030 (48) | offset to field `name` (id: 6) + +0x1C | 34 00 | VOffset16 | 0x0034 (52) | offset to field `bars` (id: 7) + +0x1E | 09 00 | VOffset16 | 0x0009 (9) | offset to field `bar_baz_type` (id: 8) + +0x20 | 38 00 | VOffset16 | 0x0038 (56) | offset to field `bar_baz` (id: 9) + +0x22 | 3C 00 | VOffset16 | 0x003C (60) | offset to field `accounts` (id: 10) + +0x24 | 40 00 | VOffset16 | 0x0040 (64) | offset to field `bob` (id: 11) + +0x26 | 44 00 | VOffset16 | 0x0044 (68) | offset to field `alice` (id: 12) + +0x28 | 00 00 | VOffset16 | 0x0000 (0) | offset to field `maybe_i32` (id: 13) (Int) + +0x2A | 00 00 | VOffset16 | 0x0000 (0) | offset to field `default_i32` (id: 14) (Int) + +0x2C | 48 00 | VOffset16 | 0x0048 (72) | offset to field `just_i32` (id: 15) + +0x2E | 4C 00 | VOffset16 | 0x004C (76) | offset to field `names` (id: 16) + +0x30 | 50 00 | VOffset16 | 0x0050 (80) | offset to field `points_of_interest` (id: 17) + +0x32 | 54 00 | VOffset16 | 0x0054 (84) | ERROR: offset to field `foobars_type` (id: 18). Invalid offset, points to outside the binary. + +0x34 | 58 00 | VOffset16 | 0x0058 (88) | ERROR: offset to field `foobars` (id: 19). Invalid offset, points to outside the binary. + +0x36 | 0A 00 | VOffset16 | 0x000A (10) | offset to field `measurement_type` (id: 20) + +0x38 | 5C 00 | VOffset16 | 0x005C (92) | ERROR: offset to field `measurement` (id: 21). Invalid offset, points to outside the binary. + +0x3A | 0B 00 | VOffset16 | 0x000B (11) | offset to field `anything_type` (id: 22) + +0x3C | 60 00 | VOffset16 | 0x0060 (96) | ERROR: offset to field `anything` (id: 23). Invalid offset, points to outside the binary. + +0x3E | 00 00 | VOffset16 | 0x0000 (0) | offset to field `temperature` (id: 24) (Float) + +0x40 | 00 00 | VOffset16 | 0x0000 (0) | offset to field `teetotaler` (id: 25) (Obj) + +0x42 | 64 00 | VOffset16 | 0x0064 (100) | ERROR: offset to field `charlie` (id: 26). Invalid offset, points to outside the binary. + +0x3A | 0B 00 | VOffset16 | 0x000B (11) | offset to unknown field (id: 22) + +0x3C | 60 00 | VOffset16 | 0x0060 (96) | offset to unknown field (id: 23) + +0x3E | 00 00 | VOffset16 | 0x0000 (0) | offset to unknown field (id: 24) + +0x40 | 00 00 | VOffset16 | 0x0000 (0) | offset to unknown field (id: 25) + +0x42 | 64 00 | VOffset16 | 0x0064 (100) | offset to unknown field (id: 26) + +root_table (AnnotatedBinary.Foo): + +0x44 | 3A 00 00 00 | SOffset32 | 0x0000003A (58) Loc: +0x0A | offset to vtable + +0x48 | 00 00 00 | uint8_t[3] | ... | padding + +0x4B | 01 | uint8_t | 0x01 (1) | table field `healthy` (Bool) + +0x4C | 02 | uint8_t | 0x02 (2) | table field `meal` (Byte) + +0x4D | 02 | UType8 | 0x02 (2) | table field `bar_baz_type` (UType) + +0x4E | 01 | UType8 | 0x01 (1) | table field `measurement_type` (UType) + +0x4F | 01 | UType8 | 0x01 (1) | table field `anything_type` (UType) + +0x50 | D2 04 00 00 | uint32_t | 0x000004D2 (1234) | table field `counter` (Int) + +0x54 | 28 02 00 00 | UOffset32 | 0x00000228 (552) Loc: +0x27C | ERROR: offset to field `bar`. Location is outside the binary. + +0x58 | 01 00 00 00 | uint32_t | 0x00000001 (1) | struct field `AnnotatedBinary.Building.floors` (Int) + +0x5C | 02 00 00 00 | uint32_t | 0x00000002 (2) | struct field `AnnotatedBinary.Building.doors` (Int) + +0x60 | 0C 00 00 00 | uint32_t | 0x0000000C (12) | struct field `AnnotatedBinary.Building.windows` (Int) + +0x64 | 0A 00 00 00 | uint32_t | 0x0000000A (10) | array field `AnnotatedBinary.Dimension.values[0]` (Int) + +0x68 | 0C 00 00 00 | uint32_t | 0x0000000C (12) | array field `AnnotatedBinary.Dimension.values[1]` (Int) + +0x6C | 14 00 00 00 | uint32_t | 0x00000014 (20) | array field `AnnotatedBinary.Dimension.values[2]` (Int) + +0x70 | 01 | uint8_t | 0x01 (1) | struct field `AnnotatedBinary.Tolerance.width` (UByte) + +0x71 | 02 | uint8_t | 0x02 (2) | struct field `AnnotatedBinary.Tolerance.width` (UByte) + +0x72 | 03 | uint8_t | 0x03 (3) | struct field `AnnotatedBinary.Tolerance.width` (UByte) + +0x73 | 00 | uint8_t[1] | . | padding + +0x74 | C8 01 00 00 | UOffset32 | 0x000001C8 (456) Loc: +0x23C | ERROR: offset to field `name`. Location is outside the binary. + +0x78 | 5C 01 00 00 | UOffset32 | 0x0000015C (348) Loc: +0x1D4 | ERROR: offset to field `bars`. Location is outside the binary. + +0x7C | 50 01 00 00 | UOffset32 | 0x00000150 (336) Loc: +0x1CC | ERROR: offset to field `bar_baz`. Location is outside the binary. + +0x80 | 34 01 00 00 | UOffset32 | 0x00000134 (308) Loc: +0x1B4 | ERROR: offset to field `accounts`. Location is outside the binary. + +0x84 | 24 01 00 00 | UOffset32 | 0x00000124 (292) Loc: +0x1A8 | ERROR: offset to field `bob`. Location is outside the binary. + +0x88 | 14 01 00 00 | UOffset32 | 0x00000114 (276) Loc: +0x19C | ERROR: offset to field `alice`. Location is outside the binary. + +0x8C | 0D 00 00 00 | uint32_t | 0x0000000D (13) | table field `just_i32` (Int) + +0x90 | DC 00 00 00 | UOffset32 | 0x000000DC (220) Loc: +0x16C | ERROR: offset to field `names`. Location is outside the binary. + +0x94 | A0 00 | ?uint8_t[2] | .. | ERROR: offset to field `points_of_interest`. Incomplete binary, expected to read 4 bytes here diff --git a/tests/annotated_binary/tests/invalid_table_field_offset.bin b/tests/annotated_binary/tests/invalid_table_field_offset.bin new file mode 100644 index 0000000000000000000000000000000000000000..f3a79edf6feb8b009b95d5906ae93bb47b77fd54 GIT binary patch literal 150 zcmXAhEe?ZV5Jca8kkImzRD4H3R8}AeLC^$&AQVx7Kp-kO7RRYZ_b^Q8CNGnn+1VC& z4#Nv7R#GDE7jAeS6kI8(X=vp_N6*NciI|y$<#a!4o@36L?IGM9m@J7tqU*nUskwl! Q!dZ->5V`OoQ~nbh2bz`(YXATM literal 0 HcmV?d00001 diff --git a/tests/annotated_binary/tests/invalid_table_field_size.afb b/tests/annotated_binary/tests/invalid_table_field_size.afb new file mode 100644 index 000000000..9c6835c08 --- /dev/null +++ b/tests/annotated_binary/tests/invalid_table_field_size.afb @@ -0,0 +1,68 @@ +// Annotated Flatbuffer Binary +// +// Schema file: annotated_binary.fbs +// Binary file: tests/invalid_table_field_size.bin + +header: + +0x00 | 44 00 00 00 | UOffset32 | 0x00000044 (68) Loc: +0x44 | offset to root table `AnnotatedBinary.Foo` + +0x04 | 41 4E 4E 4F | char[4] | ANNO | File Identifier + +padding: + +0x08 | 00 00 | uint8_t[2] | .. | padding + +vtable (AnnotatedBinary.Foo): + +0x0A | 3A 00 | uint16_t | 0x003A (58) | size of this vtable + +0x0C | 68 00 | uint16_t | 0x0068 (104) | ERROR: size of referring table. Size of table is larger than the binary. + +0x0E | 0C 00 | VOffset16 | 0x000C (12) | offset to field `counter` (id: 0) + +0x10 | 07 00 | VOffset16 | 0x0007 (7) | offset to field `healthy` (id: 1) + +0x12 | 00 00 | VOffset16 | 0x0000 (0) | offset to field `level` (id: 2) (Long) + +0x14 | 08 00 | VOffset16 | 0x0008 (8) | offset to field `meal` (id: 3) + +0x16 | 10 00 | VOffset16 | 0x0010 (16) | ERROR: offset to field `bar` (id: 4). Invalid offset, points to outside the binary. + +0x18 | 14 00 | VOffset16 | 0x0014 (20) | ERROR: offset to field `home` (id: 5). Invalid offset, points to outside the binary. + +0x1A | 30 00 | VOffset16 | 0x0030 (48) | ERROR: offset to field `name` (id: 6). Invalid offset, points to outside the binary. + +0x1C | 34 00 | VOffset16 | 0x0034 (52) | ERROR: offset to field `bars` (id: 7). Invalid offset, points to outside the binary. + +0x1E | 09 00 | VOffset16 | 0x0009 (9) | offset to field `bar_baz_type` (id: 8) + +0x20 | 38 00 | VOffset16 | 0x0038 (56) | ERROR: offset to field `bar_baz` (id: 9). Invalid offset, points to outside the binary. + +0x22 | 3C 00 | VOffset16 | 0x003C (60) | ERROR: offset to field `accounts` (id: 10). Invalid offset, points to outside the binary. + +0x24 | 40 00 | VOffset16 | 0x0040 (64) | ERROR: offset to field `bob` (id: 11). Invalid offset, points to outside the binary. + +0x26 | 44 00 | VOffset16 | 0x0044 (68) | ERROR: offset to field `alice` (id: 12). Invalid offset, points to outside the binary. + +0x28 | 00 00 | VOffset16 | 0x0000 (0) | offset to field `maybe_i32` (id: 13) (Int) + +0x2A | 00 00 | VOffset16 | 0x0000 (0) | offset to field `default_i32` (id: 14) (Int) + +0x2C | 48 00 | VOffset16 | 0x0048 (72) | ERROR: offset to field `just_i32` (id: 15). Invalid offset, points to outside the binary. + +0x2E | 4C 00 | VOffset16 | 0x004C (76) | ERROR: offset to field `names` (id: 16). Invalid offset, points to outside the binary. + +0x30 | 50 00 | VOffset16 | 0x0050 (80) | ERROR: offset to field `points_of_interest` (id: 17). Invalid offset, points to outside the binary. + +0x32 | 54 00 | VOffset16 | 0x0054 (84) | ERROR: offset to field `foobars_type` (id: 18). Invalid offset, points to outside the binary. + +0x34 | 58 00 | VOffset16 | 0x0058 (88) | ERROR: offset to field `foobars` (id: 19). Invalid offset, points to outside the binary. + +0x36 | 0A 00 | VOffset16 | 0x000A (10) | offset to field `measurement_type` (id: 20) + +0x38 | 5C 00 | VOffset16 | 0x005C (92) | ERROR: offset to field `measurement` (id: 21). Invalid offset, points to outside the binary. + +0x3A | 0B 00 | VOffset16 | 0x000B (11) | offset to field `anything_type` (id: 22) + +0x3C | 60 00 | VOffset16 | 0x0060 (96) | ERROR: offset to field `anything` (id: 23). Invalid offset, points to outside the binary. + +0x3E | 00 00 | VOffset16 | 0x0000 (0) | offset to field `temperature` (id: 24) (Float) + +0x40 | 00 00 | VOffset16 | 0x0000 (0) | offset to field `teetotaler` (id: 25) (Obj) + +0x42 | 64 00 | VOffset16 | 0x0064 (100) | ERROR: offset to field `charlie` (id: 26). Invalid offset, points to outside the binary. + +0x24 | 40 00 | VOffset16 | 0x0040 (64) | offset to unknown field (id: 11) + +0x26 | 44 00 | VOffset16 | 0x0044 (68) | offset to unknown field (id: 12) + +0x28 | 00 00 | VOffset16 | 0x0000 (0) | offset to unknown field (id: 13) + +0x2A | 00 00 | VOffset16 | 0x0000 (0) | offset to unknown field (id: 14) + +0x2C | 48 00 | VOffset16 | 0x0048 (72) | offset to unknown field (id: 15) + +0x2E | 4C 00 | VOffset16 | 0x004C (76) | offset to unknown field (id: 16) + +0x30 | 50 00 | VOffset16 | 0x0050 (80) | offset to unknown field (id: 17) + +0x32 | 54 00 | VOffset16 | 0x0054 (84) | offset to unknown field (id: 18) + +0x34 | 58 00 | VOffset16 | 0x0058 (88) | offset to unknown field (id: 19) + +0x36 | 0A 00 | VOffset16 | 0x000A (10) | offset to unknown field (id: 20) + +0x38 | 5C 00 | VOffset16 | 0x005C (92) | offset to unknown field (id: 21) + +0x3A | 0B 00 | VOffset16 | 0x000B (11) | offset to unknown field (id: 22) + +0x3C | 60 00 | VOffset16 | 0x0060 (96) | offset to unknown field (id: 23) + +0x3E | 00 00 | VOffset16 | 0x0000 (0) | offset to unknown field (id: 24) + +0x40 | 00 00 | VOffset16 | 0x0000 (0) | offset to unknown field (id: 25) + +0x42 | 64 00 | VOffset16 | 0x0064 (100) | offset to unknown field (id: 26) + +root_table (AnnotatedBinary.Foo): + +0x44 | 3A 00 00 00 | SOffset32 | 0x0000003A (58) Loc: +0x0A | offset to vtable + +0x48 | 00 00 00 | uint8_t[3] | ... | padding + +0x4B | 01 | uint8_t | 0x01 (1) | table field `healthy` (Bool) + +0x4C | 02 | uint8_t | 0x02 (2) | table field `meal` (Byte) + +0x4D | 02 | UType8 | 0x02 (2) | table field `bar_baz_type` (UType) + +0x4E | 01 | UType8 | 0x01 (1) | table field `measurement_type` (UType) + +0x4F | 01 | UType8 | 0x01 (1) | table field `anything_type` (UType) + +0x50 | D2 04 | ?uint8_t[2] | .. | ERROR: table field `counter` (Int). Expected 4 bytes. diff --git a/tests/annotated_binary/tests/invalid_table_field_size.bin b/tests/annotated_binary/tests/invalid_table_field_size.bin new file mode 100644 index 0000000000000000000000000000000000000000..4fbbbdfed4581242c334a8a750c27a3f35b629d5 GIT binary patch literal 82 zcmZ=^U|?|c^Ydq5uwuwy;9+0~@;Mj;7(^Hh7)%&A87vrV7#tW}fT9cx9t=JV0SqAw b5e!@mF$~-c31HC_piVGgWMX1uyu<vc` literal 0 HcmV?d00001 diff --git a/tests/annotated_binary/tests/invalid_union_type_value.afb b/tests/annotated_binary/tests/invalid_union_type_value.afb new file mode 100644 index 000000000..59f2494dc --- /dev/null +++ b/tests/annotated_binary/tests/invalid_union_type_value.afb @@ -0,0 +1,293 @@ +// Annotated Flatbuffer Binary +// +// Schema file: annotated_binary.fbs +// Binary file: tests/invalid_union_type_value.bin + +header: + +0x0000 | 44 00 00 00 | UOffset32 | 0x00000044 (68) Loc: +0x0044 | offset to root table `AnnotatedBinary.Foo` + +0x0004 | 41 4E 4E 4F | char[4] | ANNO | File Identifier + +padding: + +0x0008 | 00 00 | uint8_t[2] | .. | padding + +vtable (AnnotatedBinary.Foo): + +0x000A | 3A 00 | uint16_t | 0x003A (58) | size of this vtable + +0x000C | 68 00 | uint16_t | 0x0068 (104) | size of referring table + +0x000E | 0C 00 | VOffset16 | 0x000C (12) | offset to field `counter` (id: 0) + +0x0010 | 07 00 | VOffset16 | 0x0007 (7) | offset to field `healthy` (id: 1) + +0x0012 | 00 00 | VOffset16 | 0x0000 (0) | offset to field `level` (id: 2) (Long) + +0x0014 | 08 00 | VOffset16 | 0x0008 (8) | offset to field `meal` (id: 3) + +0x0016 | 10 00 | VOffset16 | 0x0010 (16) | offset to field `bar` (id: 4) + +0x0018 | 14 00 | VOffset16 | 0x0014 (20) | offset to field `home` (id: 5) + +0x001A | 30 00 | VOffset16 | 0x0030 (48) | offset to field `name` (id: 6) + +0x001C | 34 00 | VOffset16 | 0x0034 (52) | offset to field `bars` (id: 7) + +0x001E | 09 00 | VOffset16 | 0x0009 (9) | offset to field `bar_baz_type` (id: 8) + +0x0020 | 38 00 | VOffset16 | 0x0038 (56) | offset to field `bar_baz` (id: 9) + +0x0022 | 3C 00 | VOffset16 | 0x003C (60) | offset to field `accounts` (id: 10) + +0x0024 | 40 00 | VOffset16 | 0x0040 (64) | offset to field `bob` (id: 11) + +0x0026 | 44 00 | VOffset16 | 0x0044 (68) | offset to field `alice` (id: 12) + +0x0028 | 00 00 | VOffset16 | 0x0000 (0) | offset to field `maybe_i32` (id: 13) (Int) + +0x002A | 00 00 | VOffset16 | 0x0000 (0) | offset to field `default_i32` (id: 14) (Int) + +0x002C | 48 00 | VOffset16 | 0x0048 (72) | offset to field `just_i32` (id: 15) + +0x002E | 4C 00 | VOffset16 | 0x004C (76) | offset to field `names` (id: 16) + +0x0030 | 50 00 | VOffset16 | 0x0050 (80) | offset to field `points_of_interest` (id: 17) + +0x0032 | 54 00 | VOffset16 | 0x0054 (84) | offset to field `foobars_type` (id: 18) + +0x0034 | 58 00 | VOffset16 | 0x0058 (88) | offset to field `foobars` (id: 19) + +0x0036 | 0A 00 | VOffset16 | 0x000A (10) | offset to field `measurement_type` (id: 20) + +0x0038 | 5C 00 | VOffset16 | 0x005C (92) | offset to field `measurement` (id: 21) + +0x003A | 0B 00 | VOffset16 | 0x000B (11) | offset to field `anything_type` (id: 22) + +0x003C | 60 00 | VOffset16 | 0x0060 (96) | offset to field `anything` (id: 23) + +0x003E | 00 00 | VOffset16 | 0x0000 (0) | offset to field `temperature` (id: 24) (Float) + +0x0040 | 00 00 | VOffset16 | 0x0000 (0) | offset to field `teetotaler` (id: 25) (Obj) + +0x0042 | 64 00 | VOffset16 | 0x0064 (100) | offset to field `charlie` (id: 26) + +root_table (AnnotatedBinary.Foo): + +0x0044 | 3A 00 00 00 | SOffset32 | 0x0000003A (58) Loc: +0x000A | offset to vtable + +0x0048 | 00 00 00 | uint8_t[3] | ... | padding + +0x004B | 01 | uint8_t | 0x01 (1) | table field `healthy` (Bool) + +0x004C | 02 | uint8_t | 0x02 (2) | table field `meal` (Byte) + +0x004D | FF | UType8 | 0xFF (255) | ERROR: table field `bar_baz_type` (UType) . Invalid union type value. + +0x004E | 01 | UType8 | 0x01 (1) | table field `measurement_type` (UType) + +0x004F | 01 | UType8 | 0x01 (1) | table field `anything_type` (UType) + +0x0050 | D2 04 00 00 | uint32_t | 0x000004D2 (1234) | table field `counter` (Int) + +0x0054 | 28 02 00 00 | UOffset32 | 0x00000228 (552) Loc: +0x027C | offset to field `bar` (table) + +0x0058 | 01 00 00 00 | uint32_t | 0x00000001 (1) | struct field `AnnotatedBinary.Building.floors` (Int) + +0x005C | 02 00 00 00 | uint32_t | 0x00000002 (2) | struct field `AnnotatedBinary.Building.doors` (Int) + +0x0060 | 0C 00 00 00 | uint32_t | 0x0000000C (12) | struct field `AnnotatedBinary.Building.windows` (Int) + +0x0064 | 0A 00 00 00 | uint32_t | 0x0000000A (10) | array field `AnnotatedBinary.Dimension.values[0]` (Int) + +0x0068 | 0C 00 00 00 | uint32_t | 0x0000000C (12) | array field `AnnotatedBinary.Dimension.values[1]` (Int) + +0x006C | 14 00 00 00 | uint32_t | 0x00000014 (20) | array field `AnnotatedBinary.Dimension.values[2]` (Int) + +0x0070 | 01 | uint8_t | 0x01 (1) | struct field `AnnotatedBinary.Tolerance.width` (UByte) + +0x0071 | 02 | uint8_t | 0x02 (2) | struct field `AnnotatedBinary.Tolerance.width` (UByte) + +0x0072 | 03 | uint8_t | 0x03 (3) | struct field `AnnotatedBinary.Tolerance.width` (UByte) + +0x0073 | 00 | uint8_t[1] | . | padding + +0x0074 | C8 01 00 00 | UOffset32 | 0x000001C8 (456) Loc: +0x023C | offset to field `name` (string) + +0x0078 | 5C 01 00 00 | UOffset32 | 0x0000015C (348) Loc: +0x01D4 | offset to field `bars` (vector) + +0x007C | 50 01 00 00 | ?uint8_t[4] | P... | WARN: nothing refers to this region. + +0x0080 | 34 01 00 00 | UOffset32 | 0x00000134 (308) Loc: +0x01B4 | offset to field `accounts` (vector) + +0x0084 | 24 01 00 00 | UOffset32 | 0x00000124 (292) Loc: +0x01A8 | offset to field `bob` (string) + +0x0088 | 14 01 00 00 | UOffset32 | 0x00000114 (276) Loc: +0x019C | offset to field `alice` (string) + +0x008C | 0D 00 00 00 | uint32_t | 0x0000000D (13) | table field `just_i32` (Int) + +0x0090 | DC 00 00 00 | UOffset32 | 0x000000DC (220) Loc: +0x016C | offset to field `names` (vector) + +0x0094 | A0 00 00 00 | UOffset32 | 0x000000A0 (160) Loc: +0x0134 | offset to field `points_of_interest` (vector) + +0x0098 | 94 00 00 00 | UOffset32 | 0x00000094 (148) Loc: +0x012C | offset to field `foobars_type` (vector) + +0x009C | 38 00 00 00 | UOffset32 | 0x00000038 (56) Loc: +0x00D4 | offset to field `foobars` (vector) + +0x00A0 | 33 00 00 00 | UOffset32 | 0x00000033 (51) Loc: +0x00D3 | offset to field `measurement` (union of type `Tolerance`) + +0x00A4 | 1C 00 00 00 | UOffset32 | 0x0000001C (28) Loc: +0x00C0 | offset to field `anything` (union of type `Bar`) + +0x00A8 | 04 00 00 00 | UOffset32 | 0x00000004 (4) Loc: +0x00AC | offset to field `charlie` (string) + +string (AnnotatedBinary.Foo.charlie): + +0x00AC | 05 00 00 00 | uint32_t | 0x00000005 (5) | length of string + +0x00B0 | 61 6C 69 63 65 | char[5] | alice + +0x00B5 | 00 | char | 0x00 (0) | string terminator + +padding: + +0x00B6 | 00 00 | uint8_t[2] | .. | padding + +vtable (AnnotatedBinary.Bar): + +0x00B8 | 08 00 | uint16_t | 0x0008 (8) | size of this vtable + +0x00BA | 13 00 | uint16_t | 0x0013 (19) | size of referring table + +0x00BC | 08 00 | VOffset16 | 0x0008 (8) | offset to field `a` (id: 0) + +0x00BE | 04 00 | VOffset16 | 0x0004 (4) | offset to field `b` (id: 1) + +table (AnnotatedBinary.Bar): + +0x00C0 | 08 00 00 00 | SOffset32 | 0x00000008 (8) Loc: +0x00B8 | offset to vtable + +0x00C4 | 00 80 23 44 | float | 0x44238000 (654.000000) | table field `b` (Float) + +0x00C8 | 00 00 00 00 00 10 74 40 | double | 0x4074100000000000 (321.000000) | table field `a` (Double) + +0x00D0 | 00 00 00 | uint8_t[3] | ... | padding + +union (AnnotatedBinary.Tolerance.measurement): + +0x00D3 | 05 | uint8_t | 0x05 (5) | struct field `AnnotatedBinary.Tolerance.width` (UByte) + +vector (AnnotatedBinary.Foo.foobars): + +0x00D4 | 03 00 00 00 | uint32_t | 0x00000003 (3) | length of vector (# items) + +0x00D8 | 34 00 00 00 | UOffset32 | 0x00000034 (52) Loc: +0x010C | offset to union[0] (`Bar`) + +0x00DC | 2C 00 00 00 | UOffset32 | 0x0000002C (44) Loc: +0x0108 | offset to union[1] (`Baz`) + +0x00E0 | 04 00 00 00 | UOffset32 | 0x00000004 (4) Loc: +0x00E4 | offset to union[2] (`Bar`) + +table (AnnotatedBinary.Bar): + +0x00E4 | D2 FE FF FF | SOffset32 | 0xFFFFFED2 (-302) Loc: +0x0212 | offset to vtable + +0x00E8 | 00 80 23 44 | float | 0x44238000 (654.000000) | table field `b` (Float) + +0x00EC | 10 00 00 00 | UOffset32 | 0x00000010 (16) Loc: +0x00FC | offset to field `c` (table) + +0x00F0 | 00 00 00 00 00 D8 8E 40 | double | 0x408ED80000000000 (987.000000) | table field `a` (Double) + +0x00F8 | 00 00 00 00 | uint8_t[4] | .... | padding + +table (AnnotatedBinary.Baz): + +0x00FC | 6A FE FF FF | SOffset32 | 0xFFFFFE6A (-406) Loc: +0x0292 | offset to vtable + +0x0100 | 00 00 00 | uint8_t[3] | ... | padding + +0x0103 | 03 | uint8_t | 0x03 (3) | table field `meal` (Byte) + +vtable (AnnotatedBinary.Baz): + +0x0104 | 04 00 | uint16_t | 0x0004 (4) | size of this vtable + +0x0106 | 04 00 | uint16_t | 0x0004 (4) | size of referring table + +table (AnnotatedBinary.Baz): + +0x0108 | 04 00 00 00 | SOffset32 | 0x00000004 (4) Loc: +0x0104 | offset to vtable + +table (AnnotatedBinary.Bar): + +0x010C | FA FE FF FF | SOffset32 | 0xFFFFFEFA (-262) Loc: +0x0212 | offset to vtable + +0x0110 | 00 00 E4 43 | float | 0x43E40000 (456.000000) | table field `b` (Float) + +0x0114 | 10 00 00 00 | UOffset32 | 0x00000010 (16) Loc: +0x0124 | offset to field `c` (table) + +0x0118 | 00 00 00 00 00 C0 5E 40 | double | 0x405EC00000000000 (123.000000) | table field `a` (Double) + +0x0120 | 00 00 00 00 | uint8_t[4] | .... | padding + +table (AnnotatedBinary.Baz): + +0x0124 | 92 FE FF FF | SOffset32 | 0xFFFFFE92 (-366) Loc: +0x0292 | offset to vtable + +0x0128 | 00 00 00 | uint8_t[3] | ... | padding + +0x012B | 01 | uint8_t | 0x01 (1) | table field `meal` (Byte) + +vector (AnnotatedBinary.Foo.foobars_type): + +0x012C | 03 00 00 00 | uint32_t | 0x00000003 (3) | length of vector (# items) + +0x0130 | 01 | UType8 | 0x01 (1) | value[0] + +0x0131 | 02 | UType8 | 0x02 (2) | value[1] + +0x0132 | 01 | UType8 | 0x01 (1) | value[2] + +vector (AnnotatedBinary.Foo.points_of_interest): + +0x0134 | 03 00 00 00 | uint32_t | 0x00000003 (3) | length of vector (# items) + +0x0138 | 33 33 33 33 33 A3 45 40 | double | 0x4045A33333333333 (43.275000) | struct field `AnnotatedBinary.Location.latitude` (Double) + +0x0140 | 7E 57 04 FF 5B 87 53 C0 | double | 0xC053875BFF04577E (-78.114990) | struct field `AnnotatedBinary.Location.longitude` (Double) + +0x0148 | 8D F0 F6 20 04 B6 42 40 | double | 0x4042B60420F6F08D (37.422001) | struct field `AnnotatedBinary.Location.latitude` (Double) + +0x0150 | 9F 77 63 41 61 85 5E C0 | double | 0xC05E85614163779F (-122.084061) | struct field `AnnotatedBinary.Location.longitude` (Double) + +0x0158 | 8F 35 23 83 DC 35 4B C0 | double | 0xC04B35DC8323358F (-54.420792) | struct field `AnnotatedBinary.Location.latitude` (Double) + +0x0160 | F6 97 DD 93 87 C5 0A 40 | double | 0x400AC58793DD97F6 (3.346450) | struct field `AnnotatedBinary.Location.longitude` (Double) + +padding: + +0x0168 | 00 00 00 00 | uint8_t[4] | .... | padding + +vector (AnnotatedBinary.Foo.names): + +0x016C | 03 00 00 00 | uint32_t | 0x00000003 (3) | length of vector (# items) + +0x0170 | 20 00 00 00 | UOffset32 | 0x00000020 (32) Loc: +0x0190 | offset to string[0] + +0x0174 | 14 00 00 00 | UOffset32 | 0x00000014 (20) Loc: +0x0188 | offset to string[1] + +0x0178 | 04 00 00 00 | UOffset32 | 0x00000004 (4) Loc: +0x017C | offset to string[2] + +string (AnnotatedBinary.Foo.names): + +0x017C | 07 00 00 00 | uint32_t | 0x00000007 (7) | length of string + +0x0180 | 63 68 61 72 6C 69 65 | char[7] | charlie + +0x0187 | 00 | char | 0x00 (0) | string terminator + +string (AnnotatedBinary.Foo.names): + +0x0188 | 03 00 00 00 | uint32_t | 0x00000003 (3) | length of string + +0x018C | 62 6F 62 | char[3] | bob + +0x018F | 00 | char | 0x00 (0) | string terminator + +string (AnnotatedBinary.Foo.names): + +0x0190 | 05 00 00 00 | uint32_t | 0x00000005 (5) | length of string + +0x0194 | 61 6C 69 63 65 | char[5] | alice + +0x0199 | 00 | char | 0x00 (0) | string terminator + +padding: + +0x019A | 00 00 | uint8_t[2] | .. | padding + +string (AnnotatedBinary.Foo.alice): + +0x019C | 07 00 00 00 | uint32_t | 0x00000007 (7) | length of string + +0x01A0 | 63 68 61 72 6C 69 65 | char[7] | charlie + +0x01A7 | 00 | char | 0x00 (0) | string terminator + +string (AnnotatedBinary.Foo.bob): + +0x01A8 | 07 00 00 00 | uint32_t | 0x00000007 (7) | length of string + +0x01AC | 63 68 61 72 6C 69 65 | char[7] | charlie + +0x01B3 | 00 | char | 0x00 (0) | string terminator + +vector (AnnotatedBinary.Foo.accounts): + +0x01B4 | 09 00 00 00 | uint32_t | 0x00000009 (9) | length of vector (# items) + +0x01B8 | 09 00 | uint16_t | 0x0009 (9) | value[0] + +0x01BA | 08 00 | uint16_t | 0x0008 (8) | value[1] + +0x01BC | 07 00 | uint16_t | 0x0007 (7) | value[2] + +0x01BE | 01 00 | uint16_t | 0x0001 (1) | value[3] + +0x01C0 | 02 00 | uint16_t | 0x0002 (2) | value[4] + +0x01C2 | 03 00 | uint16_t | 0x0003 (3) | value[5] + +0x01C4 | 06 00 | uint16_t | 0x0006 (6) | value[6] + +0x01C6 | 05 00 | uint16_t | 0x0005 (5) | value[7] + +0x01C8 | 04 00 | uint16_t | 0x0004 (4) | value[8] + +unknown (no known references): + +0x01CA | 00 00 3A FF FF FF 00 00 | ?uint8_t[10] | ..:..... | WARN: nothing refers to this section. + +0x01D2 | 00 03 | | .. + +vector (AnnotatedBinary.Foo.bars): + +0x01D4 | 02 00 00 00 | uint32_t | 0x00000002 (2) | length of vector (# items) + +0x01D8 | 44 00 00 00 | UOffset32 | 0x00000044 (68) Loc: +0x021C | offset to table[0] + +0x01DC | 10 00 00 00 | UOffset32 | 0x00000010 (16) Loc: +0x01EC | offset to table[1] + +padding: + +0x01E0 | 00 00 | uint8_t[2] | .. | padding + +vtable (AnnotatedBinary.Bar): + +0x01E2 | 0A 00 | uint16_t | 0x000A (10) | size of this vtable + +0x01E4 | 1A 00 | uint16_t | 0x001A (26) | size of referring table + +0x01E6 | 0C 00 | VOffset16 | 0x000C (12) | offset to field `a` (id: 0) + +0x01E8 | 04 00 | VOffset16 | 0x0004 (4) | offset to field `b` (id: 1) + +0x01EA | 08 00 | VOffset16 | 0x0008 (8) | offset to field `c` (id: 2) + +table (AnnotatedBinary.Bar): + +0x01EC | 0A 00 00 00 | SOffset32 | 0x0000000A (10) Loc: +0x01E2 | offset to vtable + +0x01F0 | 00 80 23 44 | float | 0x44238000 (654.000000) | table field `b` (Float) + +0x01F4 | 18 00 00 00 | UOffset32 | 0x00000018 (24) Loc: +0x020C | offset to field `c` (table) + +0x01F8 | 00 00 00 00 00 D8 8E 40 | double | 0x408ED80000000000 (987.000000) | table field `a` (Double) + +0x0200 | 00 00 00 00 00 00 | uint8_t[6] | ...... | padding + +vtable (AnnotatedBinary.Baz): + +0x0206 | 06 00 | uint16_t | 0x0006 (6) | size of this vtable + +0x0208 | 06 00 | uint16_t | 0x0006 (6) | size of referring table + +0x020A | 05 00 | VOffset16 | 0x0005 (5) | offset to field `meal` (id: 0) + +table (AnnotatedBinary.Baz): + +0x020C | 06 00 00 00 | SOffset32 | 0x00000006 (6) Loc: +0x0206 | offset to vtable + +0x0210 | 00 | uint8_t[1] | . | padding + +0x0211 | 03 | uint8_t | 0x03 (3) | table field `meal` (Byte) + +vtable (AnnotatedBinary.Bar): + +0x0212 | 0A 00 | uint16_t | 0x000A (10) | size of this vtable + +0x0214 | 18 00 | uint16_t | 0x0018 (24) | size of referring table + +0x0216 | 0C 00 | VOffset16 | 0x000C (12) | offset to field `a` (id: 0) + +0x0218 | 04 00 | VOffset16 | 0x0004 (4) | offset to field `b` (id: 1) + +0x021A | 08 00 | VOffset16 | 0x0008 (8) | offset to field `c` (id: 2) + +table (AnnotatedBinary.Bar): + +0x021C | 0A 00 00 00 | SOffset32 | 0x0000000A (10) Loc: +0x0212 | offset to vtable + +0x0220 | 00 00 E4 43 | float | 0x43E40000 (456.000000) | table field `b` (Float) + +0x0224 | 10 00 00 00 | UOffset32 | 0x00000010 (16) Loc: +0x0234 | offset to field `c` (table) + +0x0228 | 00 00 00 00 00 C0 5E 40 | double | 0x405EC00000000000 (123.000000) | table field `a` (Double) + +0x0230 | 00 00 00 00 | uint8_t[4] | .... | padding + +table (AnnotatedBinary.Baz): + +0x0234 | A2 FF FF FF | SOffset32 | 0xFFFFFFA2 (-94) Loc: +0x0292 | offset to vtable + +0x0238 | 00 00 00 | uint8_t[3] | ... | padding + +0x023B | 01 | uint8_t | 0x01 (1) | table field `meal` (Byte) + +string (AnnotatedBinary.Foo.name): + +0x023C | 2F 00 00 00 | uint32_t | 0x0000002F (47) | length of string + +0x0240 | 54 68 69 73 20 69 73 20 | char[47] | This is + +0x0248 | 61 20 6C 6F 6E 67 20 73 | | a long s + +0x0250 | 74 72 69 6E 67 20 74 6F | | tring to + +0x0258 | 20 73 68 6F 77 20 68 6F | | show ho + +0x0260 | 77 20 69 74 20 62 72 65 | | w it bre + +0x0268 | 61 6B 73 20 75 70 2E | | aks up. + +0x026F | 00 | char | 0x00 (0) | string terminator + +padding: + +0x0270 | 00 00 | uint8_t[2] | .. | padding + +vtable (AnnotatedBinary.Bar): + +0x0272 | 0A 00 | uint16_t | 0x000A (10) | size of this vtable + +0x0274 | 16 00 | uint16_t | 0x0016 (22) | size of referring table + +0x0276 | 0C 00 | VOffset16 | 0x000C (12) | offset to field `a` (id: 0) + +0x0278 | 04 00 | VOffset16 | 0x0004 (4) | offset to field `b` (id: 1) + +0x027A | 08 00 | VOffset16 | 0x0008 (8) | offset to field `c` (id: 2) + +table (AnnotatedBinary.Bar): + +0x027C | 0A 00 00 00 | SOffset32 | 0x0000000A (10) Loc: +0x0272 | offset to vtable + +0x0280 | 65 20 71 49 | float | 0x49712065 (987654.312500) | table field `b` (Float) + +0x0284 | 14 00 00 00 | UOffset32 | 0x00000014 (20) Loc: +0x0298 | offset to field `c` (table) + +0x0288 | C9 76 BE 9F 0C 24 FE 40 | double | 0x40FE240C9FBE76C9 (123456.789000) | table field `a` (Double) + +0x0290 | 00 00 | uint8_t[2] | .. | padding + +vtable (AnnotatedBinary.Baz): + +0x0292 | 06 00 | uint16_t | 0x0006 (6) | size of this vtable + +0x0294 | 08 00 | uint16_t | 0x0008 (8) | size of referring table + +0x0296 | 07 00 | VOffset16 | 0x0007 (7) | offset to field `meal` (id: 0) + +table (AnnotatedBinary.Baz): + +0x0298 | 06 00 00 00 | SOffset32 | 0x00000006 (6) Loc: +0x0292 | offset to vtable + +0x029C | 00 00 00 | uint8_t[3] | ... | padding + +0x029F | 01 | uint8_t | 0x01 (1) | table field `meal` (Byte) diff --git a/tests/annotated_binary/tests/invalid_union_type_value.bin b/tests/annotated_binary/tests/invalid_union_type_value.bin new file mode 100644 index 0000000000000000000000000000000000000000..22f2dd5ed290e0fd71fdd2c84289098b7fdb312a GIT binary patch literal 672 zcmZXR&nrYx6vw~!>a(YRV+Z;uZ@Fp^TC&-Y|*?MNuSg#$+CoVP=?}lw^fMSrY$) zrDmhpT3N932UuBHc)sU7Y2@@i@4S2NIp^K;y$JyE$;l~T02$PyhU;2H5JeAS2%{f^ zu#sRC7{vspF^hRvSVSF`{pboSeN%>~)RPHx7=U7kjvc}5z(?to5yAsE7s)h8lI{@x5X&$?-UFPTgJnXz)e@;l7BFek5} z$_6W|Stb1jykH*DJwbvwEVS?zL@Buk(VSp?E z#w}<*j?U&bR&}A6cj<~bUC880T5yXxnNK_G1--r5#R>~e75&qCYfSWb+_}4~Z~wC8 LEHasY7Rvn%kVb1` literal 0 HcmV?d00001 diff --git a/tests/annotated_binary/tests/invalid_vector_length_cut_short.afb b/tests/annotated_binary/tests/invalid_vector_length_cut_short.afb new file mode 100644 index 000000000..a0b8964a0 --- /dev/null +++ b/tests/annotated_binary/tests/invalid_vector_length_cut_short.afb @@ -0,0 +1,140 @@ +// Annotated Flatbuffer Binary +// +// Schema file: annotated_binary.fbs +// Binary file: tests/invalid_vector_length_cut_short.bin + +header: + +0x0000 | 44 00 00 00 | UOffset32 | 0x00000044 (68) Loc: +0x0044 | offset to root table `AnnotatedBinary.Foo` + +0x0004 | 41 4E 4E 4F | char[4] | ANNO | File Identifier + +padding: + +0x0008 | 00 00 | uint8_t[2] | .. | padding + +vtable (AnnotatedBinary.Foo): + +0x000A | 3A 00 | uint16_t | 0x003A (58) | size of this vtable + +0x000C | 68 00 | uint16_t | 0x0068 (104) | size of referring table + +0x000E | 0C 00 | VOffset16 | 0x000C (12) | offset to field `counter` (id: 0) + +0x0010 | 07 00 | VOffset16 | 0x0007 (7) | offset to field `healthy` (id: 1) + +0x0012 | 00 00 | VOffset16 | 0x0000 (0) | offset to field `level` (id: 2) (Long) + +0x0014 | 08 00 | VOffset16 | 0x0008 (8) | offset to field `meal` (id: 3) + +0x0016 | 10 00 | VOffset16 | 0x0010 (16) | offset to field `bar` (id: 4) + +0x0018 | 14 00 | VOffset16 | 0x0014 (20) | offset to field `home` (id: 5) + +0x001A | 30 00 | VOffset16 | 0x0030 (48) | offset to field `name` (id: 6) + +0x001C | 34 00 | VOffset16 | 0x0034 (52) | offset to field `bars` (id: 7) + +0x001E | 09 00 | VOffset16 | 0x0009 (9) | offset to field `bar_baz_type` (id: 8) + +0x0020 | 38 00 | VOffset16 | 0x0038 (56) | offset to field `bar_baz` (id: 9) + +0x0022 | 3C 00 | VOffset16 | 0x003C (60) | offset to field `accounts` (id: 10) + +0x0024 | 40 00 | VOffset16 | 0x0040 (64) | offset to field `bob` (id: 11) + +0x0026 | 44 00 | VOffset16 | 0x0044 (68) | offset to field `alice` (id: 12) + +0x0028 | 00 00 | VOffset16 | 0x0000 (0) | offset to field `maybe_i32` (id: 13) (Int) + +0x002A | 00 00 | VOffset16 | 0x0000 (0) | offset to field `default_i32` (id: 14) (Int) + +0x002C | 48 00 | VOffset16 | 0x0048 (72) | offset to field `just_i32` (id: 15) + +0x002E | 4C 00 | VOffset16 | 0x004C (76) | offset to field `names` (id: 16) + +0x0030 | 50 00 | VOffset16 | 0x0050 (80) | offset to field `points_of_interest` (id: 17) + +0x0032 | 54 00 | VOffset16 | 0x0054 (84) | offset to field `foobars_type` (id: 18) + +0x0034 | 58 00 | VOffset16 | 0x0058 (88) | offset to field `foobars` (id: 19) + +0x0036 | 0A 00 | VOffset16 | 0x000A (10) | offset to field `measurement_type` (id: 20) + +0x0038 | 5C 00 | VOffset16 | 0x005C (92) | offset to field `measurement` (id: 21) + +0x003A | 0B 00 | VOffset16 | 0x000B (11) | offset to field `anything_type` (id: 22) + +0x003C | 60 00 | VOffset16 | 0x0060 (96) | offset to field `anything` (id: 23) + +0x003E | 00 00 | VOffset16 | 0x0000 (0) | offset to field `temperature` (id: 24) (Float) + +0x0040 | 00 00 | VOffset16 | 0x0000 (0) | offset to field `teetotaler` (id: 25) (Obj) + +0x0042 | 64 00 | VOffset16 | 0x0064 (100) | offset to field `charlie` (id: 26) + +root_table (AnnotatedBinary.Foo): + +0x0044 | 3A 00 00 00 | SOffset32 | 0x0000003A (58) Loc: +0x000A | offset to vtable + +0x0048 | 00 00 00 | uint8_t[3] | ... | padding + +0x004B | 01 | uint8_t | 0x01 (1) | table field `healthy` (Bool) + +0x004C | 02 | uint8_t | 0x02 (2) | table field `meal` (Byte) + +0x004D | 02 | UType8 | 0x02 (2) | table field `bar_baz_type` (UType) + +0x004E | 01 | UType8 | 0x01 (1) | table field `measurement_type` (UType) + +0x004F | 01 | UType8 | 0x01 (1) | table field `anything_type` (UType) + +0x0050 | D2 04 00 00 | uint32_t | 0x000004D2 (1234) | table field `counter` (Int) + +0x0054 | 28 02 00 00 | UOffset32 | 0x00000228 (552) Loc: +0x027C | ERROR: offset to field `bar`. Location is outside the binary. + +0x0058 | 01 00 00 00 | uint32_t | 0x00000001 (1) | struct field `AnnotatedBinary.Building.floors` (Int) + +0x005C | 02 00 00 00 | uint32_t | 0x00000002 (2) | struct field `AnnotatedBinary.Building.doors` (Int) + +0x0060 | 0C 00 00 00 | uint32_t | 0x0000000C (12) | struct field `AnnotatedBinary.Building.windows` (Int) + +0x0064 | 0A 00 00 00 | uint32_t | 0x0000000A (10) | array field `AnnotatedBinary.Dimension.values[0]` (Int) + +0x0068 | 0C 00 00 00 | uint32_t | 0x0000000C (12) | array field `AnnotatedBinary.Dimension.values[1]` (Int) + +0x006C | 14 00 00 00 | uint32_t | 0x00000014 (20) | array field `AnnotatedBinary.Dimension.values[2]` (Int) + +0x0070 | 01 | uint8_t | 0x01 (1) | struct field `AnnotatedBinary.Tolerance.width` (UByte) + +0x0071 | 02 | uint8_t | 0x02 (2) | struct field `AnnotatedBinary.Tolerance.width` (UByte) + +0x0072 | 03 | uint8_t | 0x03 (3) | struct field `AnnotatedBinary.Tolerance.width` (UByte) + +0x0073 | 00 | uint8_t[1] | . | padding + +0x0074 | C8 01 00 00 | UOffset32 | 0x000001C8 (456) Loc: +0x023C | ERROR: offset to field `name`. Location is outside the binary. + +0x0078 | 5C 01 00 00 | UOffset32 | 0x0000015C (348) Loc: +0x01D4 | ERROR: offset to field `bars`. Location is outside the binary. + +0x007C | 50 01 00 00 | UOffset32 | 0x00000150 (336) Loc: +0x01CC | ERROR: offset to field `bar_baz`. Location is outside the binary. + +0x0080 | 34 01 00 00 | UOffset32 | 0x00000134 (308) Loc: +0x01B4 | ERROR: offset to field `accounts`. Location is outside the binary. + +0x0084 | 24 01 00 00 | UOffset32 | 0x00000124 (292) Loc: +0x01A8 | ERROR: offset to field `bob`. Location is outside the binary. + +0x0088 | 14 01 00 00 | UOffset32 | 0x00000114 (276) Loc: +0x019C | ERROR: offset to field `alice`. Location is outside the binary. + +0x008C | 0D 00 00 00 | uint32_t | 0x0000000D (13) | table field `just_i32` (Int) + +0x0090 | DC 00 00 00 | UOffset32 | 0x000000DC (220) Loc: +0x016C | ERROR: offset to field `names`. Location is outside the binary. + +0x0094 | A0 00 00 00 | UOffset32 | 0x000000A0 (160) Loc: +0x0134 | offset to field `points_of_interest` (vector) + +0x0098 | 94 00 00 00 | UOffset32 | 0x00000094 (148) Loc: +0x012C | offset to field `foobars_type` (vector) + +0x009C | 38 00 00 00 | UOffset32 | 0x00000038 (56) Loc: +0x00D4 | offset to field `foobars` (vector) + +0x00A0 | 33 00 00 00 | UOffset32 | 0x00000033 (51) Loc: +0x00D3 | offset to field `measurement` (union of type `Tolerance`) + +0x00A4 | 1C 00 00 00 | UOffset32 | 0x0000001C (28) Loc: +0x00C0 | offset to field `anything` (union of type `Bar`) + +0x00A8 | 04 00 00 00 | UOffset32 | 0x00000004 (4) Loc: +0x00AC | offset to field `charlie` (string) + +string (AnnotatedBinary.Foo.charlie): + +0x00AC | 05 00 00 00 | uint32_t | 0x00000005 (5) | length of string + +0x00B0 | 61 6C 69 63 65 | char[5] | alice + +0x00B5 | 00 | char | 0x00 (0) | string terminator + +padding: + +0x00B6 | 00 00 | uint8_t[2] | .. | padding + +vtable (AnnotatedBinary.Bar): + +0x00B8 | 08 00 | uint16_t | 0x0008 (8) | size of this vtable + +0x00BA | 13 00 | uint16_t | 0x0013 (19) | size of referring table + +0x00BC | 08 00 | VOffset16 | 0x0008 (8) | offset to field `a` (id: 0) + +0x00BE | 04 00 | VOffset16 | 0x0004 (4) | offset to field `b` (id: 1) + +table (AnnotatedBinary.Bar): + +0x00C0 | 08 00 00 00 | SOffset32 | 0x00000008 (8) Loc: +0x00B8 | offset to vtable + +0x00C4 | 00 80 23 44 | float | 0x44238000 (654.000000) | table field `b` (Float) + +0x00C8 | 00 00 00 00 00 10 74 40 | double | 0x4074100000000000 (321.000000) | table field `a` (Double) + +0x00D0 | 00 00 00 | uint8_t[3] | ... | padding + +union (AnnotatedBinary.Tolerance.measurement): + +0x00D3 | 05 | uint8_t | 0x05 (5) | struct field `AnnotatedBinary.Tolerance.width` (UByte) + +vector (AnnotatedBinary.Foo.foobars): + +0x00D4 | 03 00 00 00 | uint32_t | 0x00000003 (3) | length of vector (# items) + +0x00D8 | 34 00 00 00 | UOffset32 | 0x00000034 (52) Loc: +0x010C | offset to union[0] (`Bar`) + +0x00DC | 2C 00 00 00 | UOffset32 | 0x0000002C (44) Loc: +0x0108 | offset to union[1] (`Baz`) + +0x00E0 | 04 00 00 00 | UOffset32 | 0x00000004 (4) Loc: +0x00E4 | offset to union[2] (`Bar`) + +table (AnnotatedBinary.Bar): + +0x00E4 | D2 FE FF FF | SOffset32 | 0xFFFFFED2 (-302) Loc: +0x0212 | ERROR: offset to vtable. Invalid offset, points to outside the binary. + +unknown (no known references): + +0x00E8 | 00 80 23 44 10 00 00 00 | ?uint8_t[28] | ..#D.... | WARN: nothing refers to this section. + +0x00F0 | 00 00 00 00 00 D8 8E 40 | | .......@ + +0x00F8 | 00 00 00 00 6A FE FF FF | | ....j... + +0x0100 | 00 00 00 03 | | .... + +vtable (AnnotatedBinary.Baz): + +0x0104 | 04 00 | uint16_t | 0x0004 (4) | size of this vtable + +0x0106 | 04 00 | uint16_t | 0x0004 (4) | size of referring table + +table (AnnotatedBinary.Baz): + +0x0108 | 04 00 00 00 | SOffset32 | 0x00000004 (4) Loc: +0x0104 | offset to vtable + +table (AnnotatedBinary.Bar): + +0x010C | FA FE FF FF | SOffset32 | 0xFFFFFEFA (-262) Loc: +0x0212 | ERROR: offset to vtable. Invalid offset, points to outside the binary. + +unknown (no known references): + +0x0110 | 00 00 E4 43 10 00 00 00 | ?uint8_t[28] | ...C.... | WARN: nothing refers to this section. + +0x0118 | 00 00 00 00 00 C0 5E 40 | | ......^@ + +0x0120 | 00 00 00 00 92 FE FF FF | | ........ + +0x0128 | 00 00 00 01 | | .... + +vector (AnnotatedBinary.Foo.foobars_type): + +0x012C | 03 00 00 00 | uint32_t | 0x00000003 (3) | length of vector (# items) + +0x0130 | 01 | UType8 | 0x01 (1) | value[0] + +0x0131 | 02 | UType8 | 0x02 (2) | value[1] + +0x0132 | 01 | UType8 | 0x01 (1) | value[2] + +vector (AnnotatedBinary.Foo.points_of_interest): + +0x0134 | 03 00 | ?uint8_t[2] | .. | ERROR: length of vector (# items). Incomplete binary, expected to read 4 bytes here diff --git a/tests/annotated_binary/tests/invalid_vector_length_cut_short.bin b/tests/annotated_binary/tests/invalid_vector_length_cut_short.bin new file mode 100644 index 0000000000000000000000000000000000000000..2d622dae1440771a0ffdb4ce1a570bfcd3538b0f GIT binary patch literal 310 zcmX|*u}T9$6h+U>ZZJ^;3vQXt6c!eOTLek5VhRh1DNlG$DA-@&Kc`0*x;gZ zuYK86h%tm^4m%Nomf}WCw_2(pW_&nY$V@63N-2HkU-BleGLn56h->M{<-^_8joM{P za (Long) + +0x0014 | 08 00 | VOffset16 | 0x0008 (8) | offset to field `meal` (id: 3) + +0x0016 | 10 00 | VOffset16 | 0x0010 (16) | offset to field `bar` (id: 4) + +0x0018 | 14 00 | VOffset16 | 0x0014 (20) | offset to field `home` (id: 5) + +0x001A | 30 00 | VOffset16 | 0x0030 (48) | offset to field `name` (id: 6) + +0x001C | 34 00 | VOffset16 | 0x0034 (52) | offset to field `bars` (id: 7) + +0x001E | 09 00 | VOffset16 | 0x0009 (9) | offset to field `bar_baz_type` (id: 8) + +0x0020 | 38 00 | VOffset16 | 0x0038 (56) | offset to field `bar_baz` (id: 9) + +0x0022 | 3C 00 | VOffset16 | 0x003C (60) | offset to field `accounts` (id: 10) + +0x0024 | 40 00 | VOffset16 | 0x0040 (64) | offset to field `bob` (id: 11) + +0x0026 | 44 00 | VOffset16 | 0x0044 (68) | offset to field `alice` (id: 12) + +0x0028 | 00 00 | VOffset16 | 0x0000 (0) | offset to field `maybe_i32` (id: 13) (Int) + +0x002A | 00 00 | VOffset16 | 0x0000 (0) | offset to field `default_i32` (id: 14) (Int) + +0x002C | 48 00 | VOffset16 | 0x0048 (72) | offset to field `just_i32` (id: 15) + +0x002E | 4C 00 | VOffset16 | 0x004C (76) | offset to field `names` (id: 16) + +0x0030 | 50 00 | VOffset16 | 0x0050 (80) | offset to field `points_of_interest` (id: 17) + +0x0032 | 54 00 | VOffset16 | 0x0054 (84) | offset to field `foobars_type` (id: 18) + +0x0034 | 58 00 | VOffset16 | 0x0058 (88) | offset to field `foobars` (id: 19) + +0x0036 | 0A 00 | VOffset16 | 0x000A (10) | offset to field `measurement_type` (id: 20) + +0x0038 | 5C 00 | VOffset16 | 0x005C (92) | offset to field `measurement` (id: 21) + +0x003A | 0B 00 | VOffset16 | 0x000B (11) | offset to field `anything_type` (id: 22) + +0x003C | 60 00 | VOffset16 | 0x0060 (96) | offset to field `anything` (id: 23) + +0x003E | 00 00 | VOffset16 | 0x0000 (0) | offset to field `temperature` (id: 24) (Float) + +0x0040 | 00 00 | VOffset16 | 0x0000 (0) | offset to field `teetotaler` (id: 25) (Obj) + +0x0042 | 64 00 | VOffset16 | 0x0064 (100) | offset to field `charlie` (id: 26) + +root_table (AnnotatedBinary.Foo): + +0x0044 | 3A 00 00 00 | SOffset32 | 0x0000003A (58) Loc: +0x000A | offset to vtable + +0x0048 | 00 00 00 | uint8_t[3] | ... | padding + +0x004B | 01 | uint8_t | 0x01 (1) | table field `healthy` (Bool) + +0x004C | 02 | uint8_t | 0x02 (2) | table field `meal` (Byte) + +0x004D | 02 | UType8 | 0x02 (2) | table field `bar_baz_type` (UType) + +0x004E | 01 | UType8 | 0x01 (1) | table field `measurement_type` (UType) + +0x004F | 01 | UType8 | 0x01 (1) | table field `anything_type` (UType) + +0x0050 | D2 04 00 00 | uint32_t | 0x000004D2 (1234) | table field `counter` (Int) + +0x0054 | 28 02 00 00 | UOffset32 | 0x00000228 (552) Loc: +0x027C | ERROR: offset to field `bar`. Location is outside the binary. + +0x0058 | 01 00 00 00 | uint32_t | 0x00000001 (1) | struct field `AnnotatedBinary.Building.floors` (Int) + +0x005C | 02 00 00 00 | uint32_t | 0x00000002 (2) | struct field `AnnotatedBinary.Building.doors` (Int) + +0x0060 | 0C 00 00 00 | uint32_t | 0x0000000C (12) | struct field `AnnotatedBinary.Building.windows` (Int) + +0x0064 | 0A 00 00 00 | uint32_t | 0x0000000A (10) | array field `AnnotatedBinary.Dimension.values[0]` (Int) + +0x0068 | 0C 00 00 00 | uint32_t | 0x0000000C (12) | array field `AnnotatedBinary.Dimension.values[1]` (Int) + +0x006C | 14 00 00 00 | uint32_t | 0x00000014 (20) | array field `AnnotatedBinary.Dimension.values[2]` (Int) + +0x0070 | 01 | uint8_t | 0x01 (1) | struct field `AnnotatedBinary.Tolerance.width` (UByte) + +0x0071 | 02 | uint8_t | 0x02 (2) | struct field `AnnotatedBinary.Tolerance.width` (UByte) + +0x0072 | 03 | uint8_t | 0x03 (3) | struct field `AnnotatedBinary.Tolerance.width` (UByte) + +0x0073 | 00 | uint8_t[1] | . | padding + +0x0074 | C8 01 00 00 | UOffset32 | 0x000001C8 (456) Loc: +0x023C | ERROR: offset to field `name`. Location is outside the binary. + +0x0078 | 5C 01 00 00 | UOffset32 | 0x0000015C (348) Loc: +0x01D4 | ERROR: offset to field `bars`. Location is outside the binary. + +0x007C | 50 01 00 00 | UOffset32 | 0x00000150 (336) Loc: +0x01CC | ERROR: offset to field `bar_baz`. Location is outside the binary. + +0x0080 | 34 01 00 00 | UOffset32 | 0x00000134 (308) Loc: +0x01B4 | offset to field `accounts` (vector) + +0x0084 | 24 01 00 00 | UOffset32 | 0x00000124 (292) Loc: +0x01A8 | offset to field `bob` (string) + +0x0088 | 14 01 00 00 | UOffset32 | 0x00000114 (276) Loc: +0x019C | offset to field `alice` (string) + +0x008C | 0D 00 00 00 | uint32_t | 0x0000000D (13) | table field `just_i32` (Int) + +0x0090 | DC 00 00 00 | UOffset32 | 0x000000DC (220) Loc: +0x016C | offset to field `names` (vector) + +0x0094 | A0 00 00 00 | UOffset32 | 0x000000A0 (160) Loc: +0x0134 | offset to field `points_of_interest` (vector) + +0x0098 | 94 00 00 00 | UOffset32 | 0x00000094 (148) Loc: +0x012C | offset to field `foobars_type` (vector) + +0x009C | 38 00 00 00 | UOffset32 | 0x00000038 (56) Loc: +0x00D4 | offset to field `foobars` (vector) + +0x00A0 | 33 00 00 00 | UOffset32 | 0x00000033 (51) Loc: +0x00D3 | offset to field `measurement` (union of type `Tolerance`) + +0x00A4 | 1C 00 00 00 | UOffset32 | 0x0000001C (28) Loc: +0x00C0 | offset to field `anything` (union of type `Bar`) + +0x00A8 | 04 00 00 00 | UOffset32 | 0x00000004 (4) Loc: +0x00AC | offset to field `charlie` (string) + +string (AnnotatedBinary.Foo.charlie): + +0x00AC | 05 00 00 00 | uint32_t | 0x00000005 (5) | length of string + +0x00B0 | 61 6C 69 63 65 | char[5] | alice + +0x00B5 | 00 | char | 0x00 (0) | string terminator + +padding: + +0x00B6 | 00 00 | uint8_t[2] | .. | padding + +vtable (AnnotatedBinary.Bar): + +0x00B8 | 08 00 | uint16_t | 0x0008 (8) | size of this vtable + +0x00BA | 13 00 | uint16_t | 0x0013 (19) | size of referring table + +0x00BC | 08 00 | VOffset16 | 0x0008 (8) | offset to field `a` (id: 0) + +0x00BE | 04 00 | VOffset16 | 0x0004 (4) | offset to field `b` (id: 1) + +table (AnnotatedBinary.Bar): + +0x00C0 | 08 00 00 00 | SOffset32 | 0x00000008 (8) Loc: +0x00B8 | offset to vtable + +0x00C4 | 00 80 23 44 | float | 0x44238000 (654.000000) | table field `b` (Float) + +0x00C8 | 00 00 00 00 00 10 74 40 | double | 0x4074100000000000 (321.000000) | table field `a` (Double) + +0x00D0 | 00 00 00 | uint8_t[3] | ... | padding + +union (AnnotatedBinary.Tolerance.measurement): + +0x00D3 | 05 | uint8_t | 0x05 (5) | struct field `AnnotatedBinary.Tolerance.width` (UByte) + +vector (AnnotatedBinary.Foo.foobars): + +0x00D4 | 03 00 00 00 | uint32_t | 0x00000003 (3) | length of vector (# items) + +0x00D8 | 34 00 00 00 | UOffset32 | 0x00000034 (52) Loc: +0x010C | offset to union[0] (`Bar`) + +0x00DC | 2C 00 00 00 | UOffset32 | 0x0000002C (44) Loc: +0x0108 | offset to union[1] (`Baz`) + +0x00E0 | 04 00 00 00 | UOffset32 | 0x00000004 (4) Loc: +0x00E4 | offset to union[2] (`Bar`) + +table (AnnotatedBinary.Bar): + +0x00E4 | D2 FE FF FF | SOffset32 | 0xFFFFFED2 (-302) Loc: +0x0212 | ERROR: offset to vtable. Invalid offset, points to outside the binary. + +unknown (no known references): + +0x00E8 | 00 80 23 44 10 00 00 00 | ?uint8_t[28] | ..#D.... | WARN: nothing refers to this section. + +0x00F0 | 00 00 00 00 00 D8 8E 40 | | .......@ + +0x00F8 | 00 00 00 00 6A FE FF FF | | ....j... + +0x0100 | 00 00 00 03 | | .... + +vtable (AnnotatedBinary.Baz): + +0x0104 | 04 00 | uint16_t | 0x0004 (4) | size of this vtable + +0x0106 | 04 00 | uint16_t | 0x0004 (4) | size of referring table + +table (AnnotatedBinary.Baz): + +0x0108 | 04 00 00 00 | SOffset32 | 0x00000004 (4) Loc: +0x0104 | offset to vtable + +table (AnnotatedBinary.Bar): + +0x010C | FA FE FF FF | SOffset32 | 0xFFFFFEFA (-262) Loc: +0x0212 | ERROR: offset to vtable. Invalid offset, points to outside the binary. + +unknown (no known references): + +0x0110 | 00 00 E4 43 10 00 00 00 | ?uint8_t[28] | ...C.... | WARN: nothing refers to this section. + +0x0118 | 00 00 00 00 00 C0 5E 40 | | ......^@ + +0x0120 | 00 00 00 00 92 FE FF FF | | ........ + +0x0128 | 00 00 00 01 | | .... + +vector (AnnotatedBinary.Foo.foobars_type): + +0x012C | 03 00 00 00 | uint32_t | 0x00000003 (3) | length of vector (# items) + +0x0130 | 01 | UType8 | 0x01 (1) | value[0] + +0x0131 | 02 | UType8 | 0x02 (2) | value[1] + +0x0132 | 01 | UType8 | 0x01 (1) | value[2] + +vector (AnnotatedBinary.Foo.points_of_interest): + +0x0134 | 03 00 00 00 | uint32_t | 0x00000003 (3) | length of vector (# items) + +0x0138 | 33 33 33 33 33 A3 45 40 | double | 0x4045A33333333333 (43.275000) | struct field `AnnotatedBinary.Location.latitude` (Double) + +0x0140 | 7E 57 04 FF 5B 87 53 C0 | double | 0xC053875BFF04577E (-78.114990) | struct field `AnnotatedBinary.Location.longitude` (Double) + +0x0148 | 8D F0 F6 20 04 B6 42 40 | double | 0x4042B60420F6F08D (37.422001) | struct field `AnnotatedBinary.Location.latitude` (Double) + +0x0150 | 9F 77 63 41 61 85 5E C0 | double | 0xC05E85614163779F (-122.084061) | struct field `AnnotatedBinary.Location.longitude` (Double) + +0x0158 | 8F 35 23 83 DC 35 4B C0 | double | 0xC04B35DC8323358F (-54.420792) | struct field `AnnotatedBinary.Location.latitude` (Double) + +0x0160 | F6 97 DD 93 87 C5 0A 40 | double | 0x400AC58793DD97F6 (3.346450) | struct field `AnnotatedBinary.Location.longitude` (Double) + +padding: + +0x0168 | 00 00 00 00 | uint8_t[4] | .... | padding + +vector (AnnotatedBinary.Foo.names): + +0x016C | 03 00 00 00 | uint32_t | 0x00000003 (3) | length of vector (# items) + +0x0170 | 20 00 00 00 | UOffset32 | 0x00000020 (32) Loc: +0x0190 | offset to string[0] + +0x0174 | 14 00 00 00 | UOffset32 | 0x00000014 (20) Loc: +0x0188 | offset to string[1] + +0x0178 | 04 00 00 00 | UOffset32 | 0x00000004 (4) Loc: +0x017C | offset to string[2] + +string (AnnotatedBinary.Foo.names): + +0x017C | 07 00 00 00 | uint32_t | 0x00000007 (7) | length of string + +0x0180 | 63 68 61 72 6C 69 65 | char[7] | charlie + +0x0187 | 00 | char | 0x00 (0) | string terminator + +string (AnnotatedBinary.Foo.names): + +0x0188 | 03 00 00 00 | uint32_t | 0x00000003 (3) | length of string + +0x018C | 62 6F 62 | char[3] | bob + +0x018F | 00 | char | 0x00 (0) | string terminator + +string (AnnotatedBinary.Foo.names): + +0x0190 | 05 00 00 00 | uint32_t | 0x00000005 (5) | length of string + +0x0194 | 61 6C 69 63 65 | char[5] | alice + +0x0199 | 00 | char | 0x00 (0) | string terminator + +padding: + +0x019A | 00 00 | uint8_t[2] | .. | padding + +string (AnnotatedBinary.Foo.alice): + +0x019C | 07 00 00 00 | uint32_t | 0x00000007 (7) | length of string + +0x01A0 | 63 68 61 72 6C 69 65 | char[7] | charlie + +0x01A7 | 00 | char | 0x00 (0) | string terminator + +string (AnnotatedBinary.Foo.bob): + +0x01A8 | 07 00 00 00 | uint32_t | 0x00000007 (7) | length of string + +0x01AC | 63 68 61 72 6C 69 65 | char[7] | charlie + +0x01B3 | 00 | char | 0x00 (0) | string terminator + +vector (AnnotatedBinary.Foo.accounts): + +0x01B4 | 09 00 00 00 | uint32_t | 0x00000009 (9) | length of vector (# items) + +0x01B8 | 09 00 | uint16_t | 0x0009 (9) | value[0] + +0x01BA | 08 00 | uint16_t | 0x0008 (8) | value[1] + +0x01BC | 07 00 | uint16_t | 0x0007 (7) | value[2] + +0x01BE | 01 00 | uint16_t | 0x0001 (1) | value[3] + +0x01C0 | 02 | ?uint8_t[1] | . | ERROR: value[4]. Incomplete binary, expected to read 2 bytes here diff --git a/tests/annotated_binary/tests/invalid_vector_scalars_cut_short.bin b/tests/annotated_binary/tests/invalid_vector_scalars_cut_short.bin new file mode 100644 index 0000000000000000000000000000000000000000..79dc7969b98275a7407c1289b702fc529be69cec GIT binary patch literal 449 zcmY+AKTE?v7{;Hwq_n9D0W&%j>fqoYG=(A#SFIo@wVBQvrw$Ir=Pn@ig1ge__Yv&1H}%Y5>K?wO*OviR}IBGG-rpE%YvF3-l^ZxET* (Long) + +0x0014 | 08 00 | VOffset16 | 0x0008 (8) | offset to field `meal` (id: 3) + +0x0016 | 10 00 | VOffset16 | 0x0010 (16) | offset to field `bar` (id: 4) + +0x0018 | 14 00 | VOffset16 | 0x0014 (20) | offset to field `home` (id: 5) + +0x001A | 30 00 | VOffset16 | 0x0030 (48) | offset to field `name` (id: 6) + +0x001C | 34 00 | VOffset16 | 0x0034 (52) | offset to field `bars` (id: 7) + +0x001E | 09 00 | VOffset16 | 0x0009 (9) | offset to field `bar_baz_type` (id: 8) + +0x0020 | 38 00 | VOffset16 | 0x0038 (56) | offset to field `bar_baz` (id: 9) + +0x0022 | 3C 00 | VOffset16 | 0x003C (60) | offset to field `accounts` (id: 10) + +0x0024 | 40 00 | VOffset16 | 0x0040 (64) | offset to field `bob` (id: 11) + +0x0026 | 44 00 | VOffset16 | 0x0044 (68) | offset to field `alice` (id: 12) + +0x0028 | 00 00 | VOffset16 | 0x0000 (0) | offset to field `maybe_i32` (id: 13) (Int) + +0x002A | 00 00 | VOffset16 | 0x0000 (0) | offset to field `default_i32` (id: 14) (Int) + +0x002C | 48 00 | VOffset16 | 0x0048 (72) | offset to field `just_i32` (id: 15) + +0x002E | 4C 00 | VOffset16 | 0x004C (76) | offset to field `names` (id: 16) + +0x0030 | 50 00 | VOffset16 | 0x0050 (80) | offset to field `points_of_interest` (id: 17) + +0x0032 | 54 00 | VOffset16 | 0x0054 (84) | offset to field `foobars_type` (id: 18) + +0x0034 | 58 00 | VOffset16 | 0x0058 (88) | offset to field `foobars` (id: 19) + +0x0036 | 0A 00 | VOffset16 | 0x000A (10) | offset to field `measurement_type` (id: 20) + +0x0038 | 5C 00 | VOffset16 | 0x005C (92) | offset to field `measurement` (id: 21) + +0x003A | 0B 00 | VOffset16 | 0x000B (11) | offset to field `anything_type` (id: 22) + +0x003C | 60 00 | VOffset16 | 0x0060 (96) | offset to field `anything` (id: 23) + +0x003E | 00 00 | VOffset16 | 0x0000 (0) | offset to field `temperature` (id: 24) (Float) + +0x0040 | 00 00 | VOffset16 | 0x0000 (0) | offset to field `teetotaler` (id: 25) (Obj) + +0x0042 | 64 00 | VOffset16 | 0x0064 (100) | offset to field `charlie` (id: 26) + +root_table (AnnotatedBinary.Foo): + +0x0044 | 3A 00 00 00 | SOffset32 | 0x0000003A (58) Loc: +0x000A | offset to vtable + +0x0048 | 00 00 00 | uint8_t[3] | ... | padding + +0x004B | 01 | uint8_t | 0x01 (1) | table field `healthy` (Bool) + +0x004C | 02 | uint8_t | 0x02 (2) | table field `meal` (Byte) + +0x004D | 02 | UType8 | 0x02 (2) | table field `bar_baz_type` (UType) + +0x004E | 01 | UType8 | 0x01 (1) | table field `measurement_type` (UType) + +0x004F | 01 | UType8 | 0x01 (1) | table field `anything_type` (UType) + +0x0050 | D2 04 00 00 | uint32_t | 0x000004D2 (1234) | table field `counter` (Int) + +0x0054 | 28 02 00 00 | UOffset32 | 0x00000228 (552) Loc: +0x027C | ERROR: offset to field `bar`. Location is outside the binary. + +0x0058 | 01 00 00 00 | uint32_t | 0x00000001 (1) | struct field `AnnotatedBinary.Building.floors` (Int) + +0x005C | 02 00 00 00 | uint32_t | 0x00000002 (2) | struct field `AnnotatedBinary.Building.doors` (Int) + +0x0060 | 0C 00 00 00 | uint32_t | 0x0000000C (12) | struct field `AnnotatedBinary.Building.windows` (Int) + +0x0064 | 0A 00 00 00 | uint32_t | 0x0000000A (10) | array field `AnnotatedBinary.Dimension.values[0]` (Int) + +0x0068 | 0C 00 00 00 | uint32_t | 0x0000000C (12) | array field `AnnotatedBinary.Dimension.values[1]` (Int) + +0x006C | 14 00 00 00 | uint32_t | 0x00000014 (20) | array field `AnnotatedBinary.Dimension.values[2]` (Int) + +0x0070 | 01 | uint8_t | 0x01 (1) | struct field `AnnotatedBinary.Tolerance.width` (UByte) + +0x0071 | 02 | uint8_t | 0x02 (2) | struct field `AnnotatedBinary.Tolerance.width` (UByte) + +0x0072 | 03 | uint8_t | 0x03 (3) | struct field `AnnotatedBinary.Tolerance.width` (UByte) + +0x0073 | 00 | uint8_t[1] | . | padding + +0x0074 | C8 01 00 00 | UOffset32 | 0x000001C8 (456) Loc: +0x023C | ERROR: offset to field `name`. Location is outside the binary. + +0x0078 | 5C 01 00 00 | UOffset32 | 0x0000015C (348) Loc: +0x01D4 | ERROR: offset to field `bars`. Location is outside the binary. + +0x007C | 50 01 00 00 | UOffset32 | 0x00000150 (336) Loc: +0x01CC | ERROR: offset to field `bar_baz`. Location is outside the binary. + +0x0080 | 34 01 00 00 | UOffset32 | 0x00000134 (308) Loc: +0x01B4 | ERROR: offset to field `accounts`. Location is outside the binary. + +0x0084 | 24 01 00 00 | UOffset32 | 0x00000124 (292) Loc: +0x01A8 | ERROR: offset to field `bob`. Location is outside the binary. + +0x0088 | 14 01 00 00 | UOffset32 | 0x00000114 (276) Loc: +0x019C | ERROR: offset to field `alice`. Location is outside the binary. + +0x008C | 0D 00 00 00 | uint32_t | 0x0000000D (13) | table field `just_i32` (Int) + +0x0090 | DC 00 00 00 | UOffset32 | 0x000000DC (220) Loc: +0x016C | offset to field `names` (vector) + +0x0094 | A0 00 00 00 | UOffset32 | 0x000000A0 (160) Loc: +0x0134 | offset to field `points_of_interest` (vector) + +0x0098 | 94 00 00 00 | UOffset32 | 0x00000094 (148) Loc: +0x012C | offset to field `foobars_type` (vector) + +0x009C | 38 00 00 00 | UOffset32 | 0x00000038 (56) Loc: +0x00D4 | offset to field `foobars` (vector) + +0x00A0 | 33 00 00 00 | UOffset32 | 0x00000033 (51) Loc: +0x00D3 | offset to field `measurement` (union of type `Tolerance`) + +0x00A4 | 1C 00 00 00 | UOffset32 | 0x0000001C (28) Loc: +0x00C0 | offset to field `anything` (union of type `Bar`) + +0x00A8 | 04 00 00 00 | UOffset32 | 0x00000004 (4) Loc: +0x00AC | offset to field `charlie` (string) + +string (AnnotatedBinary.Foo.charlie): + +0x00AC | 05 00 00 00 | uint32_t | 0x00000005 (5) | length of string + +0x00B0 | 61 6C 69 63 65 | char[5] | alice + +0x00B5 | 00 | char | 0x00 (0) | string terminator + +padding: + +0x00B6 | 00 00 | uint8_t[2] | .. | padding + +vtable (AnnotatedBinary.Bar): + +0x00B8 | 08 00 | uint16_t | 0x0008 (8) | size of this vtable + +0x00BA | 13 00 | uint16_t | 0x0013 (19) | size of referring table + +0x00BC | 08 00 | VOffset16 | 0x0008 (8) | offset to field `a` (id: 0) + +0x00BE | 04 00 | VOffset16 | 0x0004 (4) | offset to field `b` (id: 1) + +table (AnnotatedBinary.Bar): + +0x00C0 | 08 00 00 00 | SOffset32 | 0x00000008 (8) Loc: +0x00B8 | offset to vtable + +0x00C4 | 00 80 23 44 | float | 0x44238000 (654.000000) | table field `b` (Float) + +0x00C8 | 00 00 00 00 00 10 74 40 | double | 0x4074100000000000 (321.000000) | table field `a` (Double) + +0x00D0 | 00 00 00 | uint8_t[3] | ... | padding + +union (AnnotatedBinary.Tolerance.measurement): + +0x00D3 | 05 | uint8_t | 0x05 (5) | struct field `AnnotatedBinary.Tolerance.width` (UByte) + +vector (AnnotatedBinary.Foo.foobars): + +0x00D4 | 03 00 00 00 | uint32_t | 0x00000003 (3) | length of vector (# items) + +0x00D8 | 34 00 00 00 | UOffset32 | 0x00000034 (52) Loc: +0x010C | offset to union[0] (`Bar`) + +0x00DC | 2C 00 00 00 | UOffset32 | 0x0000002C (44) Loc: +0x0108 | offset to union[1] (`Baz`) + +0x00E0 | 04 00 00 00 | UOffset32 | 0x00000004 (4) Loc: +0x00E4 | offset to union[2] (`Bar`) + +table (AnnotatedBinary.Bar): + +0x00E4 | D2 FE FF FF | SOffset32 | 0xFFFFFED2 (-302) Loc: +0x0212 | ERROR: offset to vtable. Invalid offset, points to outside the binary. + +unknown (no known references): + +0x00E8 | 00 80 23 44 10 00 00 00 | ?uint8_t[28] | ..#D.... | WARN: nothing refers to this section. + +0x00F0 | 00 00 00 00 00 D8 8E 40 | | .......@ + +0x00F8 | 00 00 00 00 6A FE FF FF | | ....j... + +0x0100 | 00 00 00 03 | | .... + +vtable (AnnotatedBinary.Baz): + +0x0104 | 04 00 | uint16_t | 0x0004 (4) | size of this vtable + +0x0106 | 04 00 | uint16_t | 0x0004 (4) | size of referring table + +table (AnnotatedBinary.Baz): + +0x0108 | 04 00 00 00 | SOffset32 | 0x00000004 (4) Loc: +0x0104 | offset to vtable + +table (AnnotatedBinary.Bar): + +0x010C | FA FE FF FF | SOffset32 | 0xFFFFFEFA (-262) Loc: +0x0212 | ERROR: offset to vtable. Invalid offset, points to outside the binary. + +unknown (no known references): + +0x0110 | 00 00 E4 43 10 00 00 00 | ?uint8_t[28] | ...C.... | WARN: nothing refers to this section. + +0x0118 | 00 00 00 00 00 C0 5E 40 | | ......^@ + +0x0120 | 00 00 00 00 92 FE FF FF | | ........ + +0x0128 | 00 00 00 01 | | .... + +vector (AnnotatedBinary.Foo.foobars_type): + +0x012C | 03 00 00 00 | uint32_t | 0x00000003 (3) | length of vector (# items) + +0x0130 | 01 | UType8 | 0x01 (1) | value[0] + +0x0131 | 02 | UType8 | 0x02 (2) | value[1] + +0x0132 | 01 | UType8 | 0x01 (1) | value[2] + +vector (AnnotatedBinary.Foo.points_of_interest): + +0x0134 | 03 00 00 00 | uint32_t | 0x00000003 (3) | length of vector (# items) + +0x0138 | 33 33 33 33 33 A3 45 40 | double | 0x4045A33333333333 (43.275000) | struct field `AnnotatedBinary.Location.latitude` (Double) + +0x0140 | 7E 57 04 FF 5B 87 53 C0 | double | 0xC053875BFF04577E (-78.114990) | struct field `AnnotatedBinary.Location.longitude` (Double) + +0x0148 | 8D F0 F6 20 04 B6 42 40 | double | 0x4042B60420F6F08D (37.422001) | struct field `AnnotatedBinary.Location.latitude` (Double) + +0x0150 | 9F 77 63 41 61 85 5E C0 | double | 0xC05E85614163779F (-122.084061) | struct field `AnnotatedBinary.Location.longitude` (Double) + +0x0158 | 8F 35 23 83 DC 35 4B C0 | double | 0xC04B35DC8323358F (-54.420792) | struct field `AnnotatedBinary.Location.latitude` (Double) + +0x0160 | F6 97 DD 93 87 C5 0A 40 | double | 0x400AC58793DD97F6 (3.346450) | struct field `AnnotatedBinary.Location.longitude` (Double) + +padding: + +0x0168 | 00 00 00 00 | uint8_t[4] | .... | padding + +vector (AnnotatedBinary.Foo.names): + +0x016C | 03 00 00 00 | uint32_t | 0x00000003 (3) | length of vector (# items) + +0x0170 | 20 00 00 00 | UOffset32 | 0x00000020 (32) Loc: +0x0190 | ERROR: offset to string[0]. Invalid offset, points to outside the binary. + +0x0174 | 14 00 | ?uint8_t[2] | .. | ERROR: offset to string[1]. Incomplete binary, expected to read 4 bytes here diff --git a/tests/annotated_binary/tests/invalid_vector_strings_cut_short.bin b/tests/annotated_binary/tests/invalid_vector_strings_cut_short.bin new file mode 100644 index 0000000000000000000000000000000000000000..434aba1541a67158f489568b60ba6c9f95b14ffb GIT binary patch literal 374 zcmX|*u}T9$6h+VMZZJlLfLmGwVqsw+WCKAgCK^FdVn9K`5DZaJu@vk?5J?pU6)Y9} z2kUJF>r@u8^8>6>SQzi@f)CEzd3Wx6Obw{k>zlC15tEFm&ypu(frxP`EMck1g*7&4 zu+1(xnoO{txCfd{%6OhJ{Q%}XFtQ}th|;NsQseo&>#->sA`-JA6jOR1h-dL2DxxH2 zgw~P~?bGAVp)||12!!ggn0_#SX4PeU9g&z9Zm$138o5kf_oO~ (Long) + +0x0014 | 08 00 | VOffset16 | 0x0008 (8) | offset to field `meal` (id: 3) + +0x0016 | 10 00 | VOffset16 | 0x0010 (16) | offset to field `bar` (id: 4) + +0x0018 | 14 00 | VOffset16 | 0x0014 (20) | offset to field `home` (id: 5) + +0x001A | 30 00 | VOffset16 | 0x0030 (48) | offset to field `name` (id: 6) + +0x001C | 34 00 | VOffset16 | 0x0034 (52) | offset to field `bars` (id: 7) + +0x001E | 09 00 | VOffset16 | 0x0009 (9) | offset to field `bar_baz_type` (id: 8) + +0x0020 | 38 00 | VOffset16 | 0x0038 (56) | offset to field `bar_baz` (id: 9) + +0x0022 | 3C 00 | VOffset16 | 0x003C (60) | offset to field `accounts` (id: 10) + +0x0024 | 40 00 | VOffset16 | 0x0040 (64) | offset to field `bob` (id: 11) + +0x0026 | 44 00 | VOffset16 | 0x0044 (68) | offset to field `alice` (id: 12) + +0x0028 | 00 00 | VOffset16 | 0x0000 (0) | offset to field `maybe_i32` (id: 13) (Int) + +0x002A | 00 00 | VOffset16 | 0x0000 (0) | offset to field `default_i32` (id: 14) (Int) + +0x002C | 48 00 | VOffset16 | 0x0048 (72) | offset to field `just_i32` (id: 15) + +0x002E | 4C 00 | VOffset16 | 0x004C (76) | offset to field `names` (id: 16) + +0x0030 | 50 00 | VOffset16 | 0x0050 (80) | offset to field `points_of_interest` (id: 17) + +0x0032 | 54 00 | VOffset16 | 0x0054 (84) | offset to field `foobars_type` (id: 18) + +0x0034 | 58 00 | VOffset16 | 0x0058 (88) | offset to field `foobars` (id: 19) + +0x0036 | 0A 00 | VOffset16 | 0x000A (10) | offset to field `measurement_type` (id: 20) + +0x0038 | 5C 00 | VOffset16 | 0x005C (92) | offset to field `measurement` (id: 21) + +0x003A | 0B 00 | VOffset16 | 0x000B (11) | offset to field `anything_type` (id: 22) + +0x003C | 60 00 | VOffset16 | 0x0060 (96) | offset to field `anything` (id: 23) + +0x003E | 00 00 | VOffset16 | 0x0000 (0) | offset to field `temperature` (id: 24) (Float) + +0x0040 | 00 00 | VOffset16 | 0x0000 (0) | offset to field `teetotaler` (id: 25) (Obj) + +0x0042 | 64 00 | VOffset16 | 0x0064 (100) | offset to field `charlie` (id: 26) + +root_table (AnnotatedBinary.Foo): + +0x0044 | 3A 00 00 00 | SOffset32 | 0x0000003A (58) Loc: +0x000A | offset to vtable + +0x0048 | 00 00 00 | uint8_t[3] | ... | padding + +0x004B | 01 | uint8_t | 0x01 (1) | table field `healthy` (Bool) + +0x004C | 02 | uint8_t | 0x02 (2) | table field `meal` (Byte) + +0x004D | 02 | UType8 | 0x02 (2) | table field `bar_baz_type` (UType) + +0x004E | 01 | UType8 | 0x01 (1) | table field `measurement_type` (UType) + +0x004F | 01 | UType8 | 0x01 (1) | table field `anything_type` (UType) + +0x0050 | D2 04 00 00 | uint32_t | 0x000004D2 (1234) | table field `counter` (Int) + +0x0054 | 28 02 00 00 | UOffset32 | 0x00000228 (552) Loc: +0x027C | ERROR: offset to field `bar`. Location is outside the binary. + +0x0058 | 01 00 00 00 | uint32_t | 0x00000001 (1) | struct field `AnnotatedBinary.Building.floors` (Int) + +0x005C | 02 00 00 00 | uint32_t | 0x00000002 (2) | struct field `AnnotatedBinary.Building.doors` (Int) + +0x0060 | 0C 00 00 00 | uint32_t | 0x0000000C (12) | struct field `AnnotatedBinary.Building.windows` (Int) + +0x0064 | 0A 00 00 00 | uint32_t | 0x0000000A (10) | array field `AnnotatedBinary.Dimension.values[0]` (Int) + +0x0068 | 0C 00 00 00 | uint32_t | 0x0000000C (12) | array field `AnnotatedBinary.Dimension.values[1]` (Int) + +0x006C | 14 00 00 00 | uint32_t | 0x00000014 (20) | array field `AnnotatedBinary.Dimension.values[2]` (Int) + +0x0070 | 01 | uint8_t | 0x01 (1) | struct field `AnnotatedBinary.Tolerance.width` (UByte) + +0x0071 | 02 | uint8_t | 0x02 (2) | struct field `AnnotatedBinary.Tolerance.width` (UByte) + +0x0072 | 03 | uint8_t | 0x03 (3) | struct field `AnnotatedBinary.Tolerance.width` (UByte) + +0x0073 | 00 | uint8_t[1] | . | padding + +0x0074 | C8 01 00 00 | UOffset32 | 0x000001C8 (456) Loc: +0x023C | ERROR: offset to field `name`. Location is outside the binary. + +0x0078 | 5C 01 00 00 | UOffset32 | 0x0000015C (348) Loc: +0x01D4 | ERROR: offset to field `bars`. Location is outside the binary. + +0x007C | 50 01 00 00 | UOffset32 | 0x00000150 (336) Loc: +0x01CC | ERROR: offset to field `bar_baz`. Location is outside the binary. + +0x0080 | 34 01 00 00 | UOffset32 | 0x00000134 (308) Loc: +0x01B4 | ERROR: offset to field `accounts`. Location is outside the binary. + +0x0084 | 24 01 00 00 | UOffset32 | 0x00000124 (292) Loc: +0x01A8 | ERROR: offset to field `bob`. Location is outside the binary. + +0x0088 | 14 01 00 00 | UOffset32 | 0x00000114 (276) Loc: +0x019C | ERROR: offset to field `alice`. Location is outside the binary. + +0x008C | 0D 00 00 00 | uint32_t | 0x0000000D (13) | table field `just_i32` (Int) + +0x0090 | DC 00 00 00 | UOffset32 | 0x000000DC (220) Loc: +0x016C | ERROR: offset to field `names`. Location is outside the binary. + +0x0094 | A0 00 00 00 | UOffset32 | 0x000000A0 (160) Loc: +0x0134 | offset to field `points_of_interest` (vector) + +0x0098 | 94 00 00 00 | UOffset32 | 0x00000094 (148) Loc: +0x012C | offset to field `foobars_type` (vector) + +0x009C | 38 00 00 00 | UOffset32 | 0x00000038 (56) Loc: +0x00D4 | offset to field `foobars` (vector) + +0x00A0 | 33 00 00 00 | UOffset32 | 0x00000033 (51) Loc: +0x00D3 | offset to field `measurement` (union of type `Tolerance`) + +0x00A4 | 1C 00 00 00 | UOffset32 | 0x0000001C (28) Loc: +0x00C0 | offset to field `anything` (union of type `Bar`) + +0x00A8 | 04 00 00 00 | UOffset32 | 0x00000004 (4) Loc: +0x00AC | offset to field `charlie` (string) + +string (AnnotatedBinary.Foo.charlie): + +0x00AC | 05 00 00 00 | uint32_t | 0x00000005 (5) | length of string + +0x00B0 | 61 6C 69 63 65 | char[5] | alice + +0x00B5 | 00 | char | 0x00 (0) | string terminator + +padding: + +0x00B6 | 00 00 | uint8_t[2] | .. | padding + +vtable (AnnotatedBinary.Bar): + +0x00B8 | 08 00 | uint16_t | 0x0008 (8) | size of this vtable + +0x00BA | 13 00 | uint16_t | 0x0013 (19) | size of referring table + +0x00BC | 08 00 | VOffset16 | 0x0008 (8) | offset to field `a` (id: 0) + +0x00BE | 04 00 | VOffset16 | 0x0004 (4) | offset to field `b` (id: 1) + +table (AnnotatedBinary.Bar): + +0x00C0 | 08 00 00 00 | SOffset32 | 0x00000008 (8) Loc: +0x00B8 | offset to vtable + +0x00C4 | 00 80 23 44 | float | 0x44238000 (654.000000) | table field `b` (Float) + +0x00C8 | 00 00 00 00 00 10 74 40 | double | 0x4074100000000000 (321.000000) | table field `a` (Double) + +0x00D0 | 00 00 00 | uint8_t[3] | ... | padding + +union (AnnotatedBinary.Tolerance.measurement): + +0x00D3 | 05 | uint8_t | 0x05 (5) | struct field `AnnotatedBinary.Tolerance.width` (UByte) + +vector (AnnotatedBinary.Foo.foobars): + +0x00D4 | 03 00 00 00 | uint32_t | 0x00000003 (3) | length of vector (# items) + +0x00D8 | 34 00 00 00 | UOffset32 | 0x00000034 (52) Loc: +0x010C | offset to union[0] (`Bar`) + +0x00DC | 2C 00 00 00 | UOffset32 | 0x0000002C (44) Loc: +0x0108 | offset to union[1] (`Baz`) + +0x00E0 | 04 00 00 00 | UOffset32 | 0x00000004 (4) Loc: +0x00E4 | offset to union[2] (`Bar`) + +table (AnnotatedBinary.Bar): + +0x00E4 | D2 FE FF FF | SOffset32 | 0xFFFFFED2 (-302) Loc: +0x0212 | ERROR: offset to vtable. Invalid offset, points to outside the binary. + +unknown (no known references): + +0x00E8 | 00 80 23 44 10 00 00 00 | ?uint8_t[28] | ..#D.... | WARN: nothing refers to this section. + +0x00F0 | 00 00 00 00 00 D8 8E 40 | | .......@ + +0x00F8 | 00 00 00 00 6A FE FF FF | | ....j... + +0x0100 | 00 00 00 03 | | .... + +vtable (AnnotatedBinary.Baz): + +0x0104 | 04 00 | uint16_t | 0x0004 (4) | size of this vtable + +0x0106 | 04 00 | uint16_t | 0x0004 (4) | size of referring table + +table (AnnotatedBinary.Baz): + +0x0108 | 04 00 00 00 | SOffset32 | 0x00000004 (4) Loc: +0x0104 | offset to vtable + +table (AnnotatedBinary.Bar): + +0x010C | FA FE FF FF | SOffset32 | 0xFFFFFEFA (-262) Loc: +0x0212 | ERROR: offset to vtable. Invalid offset, points to outside the binary. + +unknown (no known references): + +0x0110 | 00 00 E4 43 10 00 00 00 | ?uint8_t[28] | ...C.... | WARN: nothing refers to this section. + +0x0118 | 00 00 00 00 00 C0 5E 40 | | ......^@ + +0x0120 | 00 00 00 00 92 FE FF FF | | ........ + +0x0128 | 00 00 00 01 | | .... + +vector (AnnotatedBinary.Foo.foobars_type): + +0x012C | 03 00 00 00 | uint32_t | 0x00000003 (3) | length of vector (# items) + +0x0130 | 01 | UType8 | 0x01 (1) | value[0] + +0x0131 | 02 | UType8 | 0x02 (2) | value[1] + +0x0132 | 01 | UType8 | 0x01 (1) | value[2] + +vector (AnnotatedBinary.Foo.points_of_interest): + +0x0134 | 03 00 00 00 | uint32_t | 0x00000003 (3) | length of vector (# items) + +0x0138 | 33 33 33 33 33 A3 45 40 | double | 0x4045A33333333333 (43.275000) | struct field `AnnotatedBinary.Location.latitude` (Double) + +0x0140 | 7E 57 04 FF 5B 87 53 C0 | double | 0xC053875BFF04577E (-78.114990) | struct field `AnnotatedBinary.Location.longitude` (Double) + +0x0148 | 8D F0 F6 20 04 B6 42 40 | double | 0x4042B60420F6F08D (37.422001) | struct field `AnnotatedBinary.Location.latitude` (Double) + +0x0150 | 9F 77 63 41 | ?uint8_t[4] | .wcA | ERROR: struct field `AnnotatedBinary.Location.longitude` (Double). Expected to read 8 bytes. diff --git a/tests/annotated_binary/tests/invalid_vector_structs_cut_short.bin b/tests/annotated_binary/tests/invalid_vector_structs_cut_short.bin new file mode 100644 index 0000000000000000000000000000000000000000..44da4088b556321d99b5048adcd7752d38b690bc GIT binary patch literal 340 zcmX|*Jxc>Y6h+U>PB4DKf?HY$rm(OOvPBS!iHTq#F`%Ge5G4vKDFf-m&PofhPayxn zI;C|g3rl~1l|>5IJGaErxY;(gBbLz{)By5o~PmLWsO}Vho0d0;s zWq}ThT;%SRUgl-2HD>By!-A0|(MFUmG?5w`@vdP (Long) + +0x0014 | 08 00 | VOffset16 | 0x0008 (8) | offset to field `meal` (id: 3) + +0x0016 | 10 00 | VOffset16 | 0x0010 (16) | offset to field `bar` (id: 4) + +0x0018 | 14 00 | VOffset16 | 0x0014 (20) | offset to field `home` (id: 5) + +0x001A | 30 00 | VOffset16 | 0x0030 (48) | offset to field `name` (id: 6) + +0x001C | 34 00 | VOffset16 | 0x0034 (52) | offset to field `bars` (id: 7) + +0x001E | 09 00 | VOffset16 | 0x0009 (9) | offset to field `bar_baz_type` (id: 8) + +0x0020 | 38 00 | VOffset16 | 0x0038 (56) | offset to field `bar_baz` (id: 9) + +0x0022 | 3C 00 | VOffset16 | 0x003C (60) | offset to field `accounts` (id: 10) + +0x0024 | 40 00 | VOffset16 | 0x0040 (64) | offset to field `bob` (id: 11) + +0x0026 | 44 00 | VOffset16 | 0x0044 (68) | offset to field `alice` (id: 12) + +0x0028 | 00 00 | VOffset16 | 0x0000 (0) | offset to field `maybe_i32` (id: 13) (Int) + +0x002A | 00 00 | VOffset16 | 0x0000 (0) | offset to field `default_i32` (id: 14) (Int) + +0x002C | 48 00 | VOffset16 | 0x0048 (72) | offset to field `just_i32` (id: 15) + +0x002E | 4C 00 | VOffset16 | 0x004C (76) | offset to field `names` (id: 16) + +0x0030 | 50 00 | VOffset16 | 0x0050 (80) | offset to field `points_of_interest` (id: 17) + +0x0032 | 54 00 | VOffset16 | 0x0054 (84) | offset to field `foobars_type` (id: 18) + +0x0034 | 58 00 | VOffset16 | 0x0058 (88) | offset to field `foobars` (id: 19) + +0x0036 | 0A 00 | VOffset16 | 0x000A (10) | offset to field `measurement_type` (id: 20) + +0x0038 | 5C 00 | VOffset16 | 0x005C (92) | offset to field `measurement` (id: 21) + +0x003A | 0B 00 | VOffset16 | 0x000B (11) | offset to field `anything_type` (id: 22) + +0x003C | 60 00 | VOffset16 | 0x0060 (96) | offset to field `anything` (id: 23) + +0x003E | 00 00 | VOffset16 | 0x0000 (0) | offset to field `temperature` (id: 24) (Float) + +0x0040 | 00 00 | VOffset16 | 0x0000 (0) | offset to field `teetotaler` (id: 25) (Obj) + +0x0042 | 64 00 | VOffset16 | 0x0064 (100) | offset to field `charlie` (id: 26) + +root_table (AnnotatedBinary.Foo): + +0x0044 | 3A 00 00 00 | SOffset32 | 0x0000003A (58) Loc: +0x000A | offset to vtable + +0x0048 | 00 00 00 | uint8_t[3] | ... | padding + +0x004B | 01 | uint8_t | 0x01 (1) | table field `healthy` (Bool) + +0x004C | 02 | uint8_t | 0x02 (2) | table field `meal` (Byte) + +0x004D | 02 | UType8 | 0x02 (2) | table field `bar_baz_type` (UType) + +0x004E | 01 | UType8 | 0x01 (1) | table field `measurement_type` (UType) + +0x004F | 01 | UType8 | 0x01 (1) | table field `anything_type` (UType) + +0x0050 | D2 04 00 00 | uint32_t | 0x000004D2 (1234) | table field `counter` (Int) + +0x0054 | 28 02 00 00 | UOffset32 | 0x00000228 (552) Loc: +0x027C | ERROR: offset to field `bar`. Location is outside the binary. + +0x0058 | 01 00 00 00 | uint32_t | 0x00000001 (1) | struct field `AnnotatedBinary.Building.floors` (Int) + +0x005C | 02 00 00 00 | uint32_t | 0x00000002 (2) | struct field `AnnotatedBinary.Building.doors` (Int) + +0x0060 | 0C 00 00 00 | uint32_t | 0x0000000C (12) | struct field `AnnotatedBinary.Building.windows` (Int) + +0x0064 | 0A 00 00 00 | uint32_t | 0x0000000A (10) | array field `AnnotatedBinary.Dimension.values[0]` (Int) + +0x0068 | 0C 00 00 00 | uint32_t | 0x0000000C (12) | array field `AnnotatedBinary.Dimension.values[1]` (Int) + +0x006C | 14 00 00 00 | uint32_t | 0x00000014 (20) | array field `AnnotatedBinary.Dimension.values[2]` (Int) + +0x0070 | 01 | uint8_t | 0x01 (1) | struct field `AnnotatedBinary.Tolerance.width` (UByte) + +0x0071 | 02 | uint8_t | 0x02 (2) | struct field `AnnotatedBinary.Tolerance.width` (UByte) + +0x0072 | 03 | uint8_t | 0x03 (3) | struct field `AnnotatedBinary.Tolerance.width` (UByte) + +0x0073 | 00 | uint8_t[1] | . | padding + +0x0074 | C8 01 00 00 | UOffset32 | 0x000001C8 (456) Loc: +0x023C | ERROR: offset to field `name`. Location is outside the binary. + +0x0078 | 5C 01 00 00 | UOffset32 | 0x0000015C (348) Loc: +0x01D4 | offset to field `bars` (vector) + +0x007C | 50 01 00 00 | UOffset32 | 0x00000150 (336) Loc: +0x01CC | offset to field `bar_baz` (union of type `Baz`) + +0x0080 | 34 01 00 00 | UOffset32 | 0x00000134 (308) Loc: +0x01B4 | offset to field `accounts` (vector) + +0x0084 | 24 01 00 00 | UOffset32 | 0x00000124 (292) Loc: +0x01A8 | offset to field `bob` (string) + +0x0088 | 14 01 00 00 | UOffset32 | 0x00000114 (276) Loc: +0x019C | offset to field `alice` (string) + +0x008C | 0D 00 00 00 | uint32_t | 0x0000000D (13) | table field `just_i32` (Int) + +0x0090 | DC 00 00 00 | UOffset32 | 0x000000DC (220) Loc: +0x016C | offset to field `names` (vector) + +0x0094 | A0 00 00 00 | UOffset32 | 0x000000A0 (160) Loc: +0x0134 | offset to field `points_of_interest` (vector) + +0x0098 | 94 00 00 00 | UOffset32 | 0x00000094 (148) Loc: +0x012C | offset to field `foobars_type` (vector) + +0x009C | 38 00 00 00 | UOffset32 | 0x00000038 (56) Loc: +0x00D4 | offset to field `foobars` (vector) + +0x00A0 | 33 00 00 00 | UOffset32 | 0x00000033 (51) Loc: +0x00D3 | offset to field `measurement` (union of type `Tolerance`) + +0x00A4 | 1C 00 00 00 | UOffset32 | 0x0000001C (28) Loc: +0x00C0 | offset to field `anything` (union of type `Bar`) + +0x00A8 | 04 00 00 00 | UOffset32 | 0x00000004 (4) Loc: +0x00AC | offset to field `charlie` (string) + +string (AnnotatedBinary.Foo.charlie): + +0x00AC | 05 00 00 00 | uint32_t | 0x00000005 (5) | length of string + +0x00B0 | 61 6C 69 63 65 | char[5] | alice + +0x00B5 | 00 | char | 0x00 (0) | string terminator + +padding: + +0x00B6 | 00 00 | uint8_t[2] | .. | padding + +vtable (AnnotatedBinary.Bar): + +0x00B8 | 08 00 | uint16_t | 0x0008 (8) | size of this vtable + +0x00BA | 13 00 | uint16_t | 0x0013 (19) | size of referring table + +0x00BC | 08 00 | VOffset16 | 0x0008 (8) | offset to field `a` (id: 0) + +0x00BE | 04 00 | VOffset16 | 0x0004 (4) | offset to field `b` (id: 1) + +table (AnnotatedBinary.Bar): + +0x00C0 | 08 00 00 00 | SOffset32 | 0x00000008 (8) Loc: +0x00B8 | offset to vtable + +0x00C4 | 00 80 23 44 | float | 0x44238000 (654.000000) | table field `b` (Float) + +0x00C8 | 00 00 00 00 00 10 74 40 | double | 0x4074100000000000 (321.000000) | table field `a` (Double) + +0x00D0 | 00 00 00 | uint8_t[3] | ... | padding + +union (AnnotatedBinary.Tolerance.measurement): + +0x00D3 | 05 | uint8_t | 0x05 (5) | struct field `AnnotatedBinary.Tolerance.width` (UByte) + +vector (AnnotatedBinary.Foo.foobars): + +0x00D4 | 03 00 00 00 | uint32_t | 0x00000003 (3) | length of vector (# items) + +0x00D8 | 34 00 00 00 | UOffset32 | 0x00000034 (52) Loc: +0x010C | offset to union[0] (`Bar`) + +0x00DC | 2C 00 00 00 | UOffset32 | 0x0000002C (44) Loc: +0x0108 | offset to union[1] (`Baz`) + +0x00E0 | 04 00 00 00 | UOffset32 | 0x00000004 (4) Loc: +0x00E4 | offset to union[2] (`Bar`) + +table (AnnotatedBinary.Bar): + +0x00E4 | D2 FE FF FF | SOffset32 | 0xFFFFFED2 (-302) Loc: +0x0212 | ERROR: offset to vtable. Invalid offset, points to outside the binary. + +unknown (no known references): + +0x00E8 | 00 80 23 44 10 00 00 00 | ?uint8_t[28] | ..#D.... | WARN: nothing refers to this section. + +0x00F0 | 00 00 00 00 00 D8 8E 40 | | .......@ + +0x00F8 | 00 00 00 00 6A FE FF FF | | ....j... + +0x0100 | 00 00 00 03 | | .... + +vtable (AnnotatedBinary.Baz): + +0x0104 | 04 00 | uint16_t | 0x0004 (4) | size of this vtable + +0x0106 | 04 00 | uint16_t | 0x0004 (4) | size of referring table + +table (AnnotatedBinary.Baz): + +0x0108 | 04 00 00 00 | SOffset32 | 0x00000004 (4) Loc: +0x0104 | offset to vtable + +table (AnnotatedBinary.Bar): + +0x010C | FA FE FF FF | SOffset32 | 0xFFFFFEFA (-262) Loc: +0x0212 | ERROR: offset to vtable. Invalid offset, points to outside the binary. + +unknown (no known references): + +0x0110 | 00 00 E4 43 10 00 00 00 | ?uint8_t[28] | ...C.... | WARN: nothing refers to this section. + +0x0118 | 00 00 00 00 00 C0 5E 40 | | ......^@ + +0x0120 | 00 00 00 00 92 FE FF FF | | ........ + +0x0128 | 00 00 00 01 | | .... + +vector (AnnotatedBinary.Foo.foobars_type): + +0x012C | 03 00 00 00 | uint32_t | 0x00000003 (3) | length of vector (# items) + +0x0130 | 01 | UType8 | 0x01 (1) | value[0] + +0x0131 | 02 | UType8 | 0x02 (2) | value[1] + +0x0132 | 01 | UType8 | 0x01 (1) | value[2] + +vector (AnnotatedBinary.Foo.points_of_interest): + +0x0134 | 03 00 00 00 | uint32_t | 0x00000003 (3) | length of vector (# items) + +0x0138 | 33 33 33 33 33 A3 45 40 | double | 0x4045A33333333333 (43.275000) | struct field `AnnotatedBinary.Location.latitude` (Double) + +0x0140 | 7E 57 04 FF 5B 87 53 C0 | double | 0xC053875BFF04577E (-78.114990) | struct field `AnnotatedBinary.Location.longitude` (Double) + +0x0148 | 8D F0 F6 20 04 B6 42 40 | double | 0x4042B60420F6F08D (37.422001) | struct field `AnnotatedBinary.Location.latitude` (Double) + +0x0150 | 9F 77 63 41 61 85 5E C0 | double | 0xC05E85614163779F (-122.084061) | struct field `AnnotatedBinary.Location.longitude` (Double) + +0x0158 | 8F 35 23 83 DC 35 4B C0 | double | 0xC04B35DC8323358F (-54.420792) | struct field `AnnotatedBinary.Location.latitude` (Double) + +0x0160 | F6 97 DD 93 87 C5 0A 40 | double | 0x400AC58793DD97F6 (3.346450) | struct field `AnnotatedBinary.Location.longitude` (Double) + +padding: + +0x0168 | 00 00 00 00 | uint8_t[4] | .... | padding + +vector (AnnotatedBinary.Foo.names): + +0x016C | 03 00 00 00 | uint32_t | 0x00000003 (3) | length of vector (# items) + +0x0170 | 20 00 00 00 | UOffset32 | 0x00000020 (32) Loc: +0x0190 | offset to string[0] + +0x0174 | 14 00 00 00 | UOffset32 | 0x00000014 (20) Loc: +0x0188 | offset to string[1] + +0x0178 | 04 00 00 00 | UOffset32 | 0x00000004 (4) Loc: +0x017C | offset to string[2] + +string (AnnotatedBinary.Foo.names): + +0x017C | 07 00 00 00 | uint32_t | 0x00000007 (7) | length of string + +0x0180 | 63 68 61 72 6C 69 65 | char[7] | charlie + +0x0187 | 00 | char | 0x00 (0) | string terminator + +string (AnnotatedBinary.Foo.names): + +0x0188 | 03 00 00 00 | uint32_t | 0x00000003 (3) | length of string + +0x018C | 62 6F 62 | char[3] | bob + +0x018F | 00 | char | 0x00 (0) | string terminator + +string (AnnotatedBinary.Foo.names): + +0x0190 | 05 00 00 00 | uint32_t | 0x00000005 (5) | length of string + +0x0194 | 61 6C 69 63 65 | char[5] | alice + +0x0199 | 00 | char | 0x00 (0) | string terminator + +padding: + +0x019A | 00 00 | uint8_t[2] | .. | padding + +string (AnnotatedBinary.Foo.alice): + +0x019C | 07 00 00 00 | uint32_t | 0x00000007 (7) | length of string + +0x01A0 | 63 68 61 72 6C 69 65 | char[7] | charlie + +0x01A7 | 00 | char | 0x00 (0) | string terminator + +string (AnnotatedBinary.Foo.bob): + +0x01A8 | 07 00 00 00 | uint32_t | 0x00000007 (7) | length of string + +0x01AC | 63 68 61 72 6C 69 65 | char[7] | charlie + +0x01B3 | 00 | char | 0x00 (0) | string terminator + +vector (AnnotatedBinary.Foo.accounts): + +0x01B4 | 09 00 00 00 | uint32_t | 0x00000009 (9) | length of vector (# items) + +0x01B8 | 09 00 | uint16_t | 0x0009 (9) | value[0] + +0x01BA | 08 00 | uint16_t | 0x0008 (8) | value[1] + +0x01BC | 07 00 | uint16_t | 0x0007 (7) | value[2] + +0x01BE | 01 00 | uint16_t | 0x0001 (1) | value[3] + +0x01C0 | 02 00 | uint16_t | 0x0002 (2) | value[4] + +0x01C2 | 03 00 | uint16_t | 0x0003 (3) | value[5] + +0x01C4 | 06 00 | uint16_t | 0x0006 (6) | value[6] + +0x01C6 | 05 00 | uint16_t | 0x0005 (5) | value[7] + +0x01C8 | 04 00 | uint16_t | 0x0004 (4) | value[8] + +padding: + +0x01CA | 00 00 | uint8_t[2] | .. | padding + +table (AnnotatedBinary.Baz): + +0x01CC | 3A FF FF FF | SOffset32 | 0xFFFFFF3A (-198) Loc: +0x0292 | ERROR: offset to vtable. Invalid offset, points to outside the binary. + +unknown (no known references): + +0x01D0 | 00 00 00 03 | ?uint8_t[4] | .... | could be a corrupted padding region (non zero) due to the length < 8 bytes. + +vector (AnnotatedBinary.Foo.bars): + +0x01D4 | 02 00 00 00 | uint32_t | 0x00000002 (2) | length of vector (# items) + +0x01D8 | 44 00 00 00 | UOffset32 | 0x00000044 (68) Loc: +0x021C | ERROR: offset to table[0]. Invalid offset, points to outside the binary. + +0x01DC | 10 00 | ?uint8_t[2] | .. | ERROR: offset to table[1]. Incomplete binary, expected to read 4 bytes here diff --git a/tests/annotated_binary/tests/invalid_vector_tables_cut_short.bin b/tests/annotated_binary/tests/invalid_vector_tables_cut_short.bin new file mode 100644 index 0000000000000000000000000000000000000000..2823d83ef925f10fd6f46340c780417c91938717 GIT binary patch literal 478 zcmY+AF-yZx6ot=AQrlF8fE^tQb#QPHnnEcKuNpy6YC%E4QcPo^m4YCGn+PJER8YZD z!T;c#MR4xqP&a>oQwIm*xd}+U@a5#)d(TbY^#D|BwN0Rc4yKUiIRghdEW(A2GM1p> zF$=6=19fa;7g;ngiTyZxKxZ7vFq9ftz`Ow{rYM{Ub|;#nD#OGZiw#mIE}0`aGR^vs zJdt}+CPgw!I2I}5_qsuwn!yaQ2;;nv{GfB9c}kglxMYEdZ}1aE(&O+wj`wRVdMJ6o zwAdwm-|_i#<*zSnYNm0U^eLIE3_NUKyAC@3aj)BsYptW!zdMfC$KP%GY~DQ0EgN)B&?WOK MQF0&IyGI=S0>Jr7NB{r; literal 0 HcmV?d00001 diff --git a/tests/annotated_binary/tests/invalid_vector_union_type_value.afb b/tests/annotated_binary/tests/invalid_vector_union_type_value.afb new file mode 100644 index 000000000..035fe4835 --- /dev/null +++ b/tests/annotated_binary/tests/invalid_vector_union_type_value.afb @@ -0,0 +1,293 @@ +// Annotated Flatbuffer Binary +// +// Schema file: annotated_binary.fbs +// Binary file: tests/invalid_vector_union_type_value.bin + +header: + +0x0000 | 44 00 00 00 | UOffset32 | 0x00000044 (68) Loc: +0x0044 | offset to root table `AnnotatedBinary.Foo` + +0x0004 | 41 4E 4E 4F | char[4] | ANNO | File Identifier + +padding: + +0x0008 | 00 00 | uint8_t[2] | .. | padding + +vtable (AnnotatedBinary.Foo): + +0x000A | 3A 00 | uint16_t | 0x003A (58) | size of this vtable + +0x000C | 68 00 | uint16_t | 0x0068 (104) | size of referring table + +0x000E | 0C 00 | VOffset16 | 0x000C (12) | offset to field `counter` (id: 0) + +0x0010 | 07 00 | VOffset16 | 0x0007 (7) | offset to field `healthy` (id: 1) + +0x0012 | 00 00 | VOffset16 | 0x0000 (0) | offset to field `level` (id: 2) (Long) + +0x0014 | 08 00 | VOffset16 | 0x0008 (8) | offset to field `meal` (id: 3) + +0x0016 | 10 00 | VOffset16 | 0x0010 (16) | offset to field `bar` (id: 4) + +0x0018 | 14 00 | VOffset16 | 0x0014 (20) | offset to field `home` (id: 5) + +0x001A | 30 00 | VOffset16 | 0x0030 (48) | offset to field `name` (id: 6) + +0x001C | 34 00 | VOffset16 | 0x0034 (52) | offset to field `bars` (id: 7) + +0x001E | 09 00 | VOffset16 | 0x0009 (9) | offset to field `bar_baz_type` (id: 8) + +0x0020 | 38 00 | VOffset16 | 0x0038 (56) | offset to field `bar_baz` (id: 9) + +0x0022 | 3C 00 | VOffset16 | 0x003C (60) | offset to field `accounts` (id: 10) + +0x0024 | 40 00 | VOffset16 | 0x0040 (64) | offset to field `bob` (id: 11) + +0x0026 | 44 00 | VOffset16 | 0x0044 (68) | offset to field `alice` (id: 12) + +0x0028 | 00 00 | VOffset16 | 0x0000 (0) | offset to field `maybe_i32` (id: 13) (Int) + +0x002A | 00 00 | VOffset16 | 0x0000 (0) | offset to field `default_i32` (id: 14) (Int) + +0x002C | 48 00 | VOffset16 | 0x0048 (72) | offset to field `just_i32` (id: 15) + +0x002E | 4C 00 | VOffset16 | 0x004C (76) | offset to field `names` (id: 16) + +0x0030 | 50 00 | VOffset16 | 0x0050 (80) | offset to field `points_of_interest` (id: 17) + +0x0032 | 54 00 | VOffset16 | 0x0054 (84) | offset to field `foobars_type` (id: 18) + +0x0034 | 58 00 | VOffset16 | 0x0058 (88) | offset to field `foobars` (id: 19) + +0x0036 | 0A 00 | VOffset16 | 0x000A (10) | offset to field `measurement_type` (id: 20) + +0x0038 | 5C 00 | VOffset16 | 0x005C (92) | offset to field `measurement` (id: 21) + +0x003A | 0B 00 | VOffset16 | 0x000B (11) | offset to field `anything_type` (id: 22) + +0x003C | 60 00 | VOffset16 | 0x0060 (96) | offset to field `anything` (id: 23) + +0x003E | 00 00 | VOffset16 | 0x0000 (0) | offset to field `temperature` (id: 24) (Float) + +0x0040 | 00 00 | VOffset16 | 0x0000 (0) | offset to field `teetotaler` (id: 25) (Obj) + +0x0042 | 64 00 | VOffset16 | 0x0064 (100) | offset to field `charlie` (id: 26) + +root_table (AnnotatedBinary.Foo): + +0x0044 | 3A 00 00 00 | SOffset32 | 0x0000003A (58) Loc: +0x000A | offset to vtable + +0x0048 | 00 00 00 | uint8_t[3] | ... | padding + +0x004B | 01 | uint8_t | 0x01 (1) | table field `healthy` (Bool) + +0x004C | 02 | uint8_t | 0x02 (2) | table field `meal` (Byte) + +0x004D | 02 | UType8 | 0x02 (2) | table field `bar_baz_type` (UType) + +0x004E | 01 | UType8 | 0x01 (1) | table field `measurement_type` (UType) + +0x004F | 01 | UType8 | 0x01 (1) | table field `anything_type` (UType) + +0x0050 | D2 04 00 00 | uint32_t | 0x000004D2 (1234) | table field `counter` (Int) + +0x0054 | 28 02 00 00 | UOffset32 | 0x00000228 (552) Loc: +0x027C | offset to field `bar` (table) + +0x0058 | 01 00 00 00 | uint32_t | 0x00000001 (1) | struct field `AnnotatedBinary.Building.floors` (Int) + +0x005C | 02 00 00 00 | uint32_t | 0x00000002 (2) | struct field `AnnotatedBinary.Building.doors` (Int) + +0x0060 | 0C 00 00 00 | uint32_t | 0x0000000C (12) | struct field `AnnotatedBinary.Building.windows` (Int) + +0x0064 | 0A 00 00 00 | uint32_t | 0x0000000A (10) | array field `AnnotatedBinary.Dimension.values[0]` (Int) + +0x0068 | 0C 00 00 00 | uint32_t | 0x0000000C (12) | array field `AnnotatedBinary.Dimension.values[1]` (Int) + +0x006C | 14 00 00 00 | uint32_t | 0x00000014 (20) | array field `AnnotatedBinary.Dimension.values[2]` (Int) + +0x0070 | 01 | uint8_t | 0x01 (1) | struct field `AnnotatedBinary.Tolerance.width` (UByte) + +0x0071 | 02 | uint8_t | 0x02 (2) | struct field `AnnotatedBinary.Tolerance.width` (UByte) + +0x0072 | 03 | uint8_t | 0x03 (3) | struct field `AnnotatedBinary.Tolerance.width` (UByte) + +0x0073 | 00 | uint8_t[1] | . | padding + +0x0074 | C8 01 00 00 | UOffset32 | 0x000001C8 (456) Loc: +0x023C | offset to field `name` (string) + +0x0078 | 5C 01 00 00 | UOffset32 | 0x0000015C (348) Loc: +0x01D4 | offset to field `bars` (vector) + +0x007C | 50 01 00 00 | UOffset32 | 0x00000150 (336) Loc: +0x01CC | offset to field `bar_baz` (union of type `Baz`) + +0x0080 | 34 01 00 00 | UOffset32 | 0x00000134 (308) Loc: +0x01B4 | offset to field `accounts` (vector) + +0x0084 | 24 01 00 00 | UOffset32 | 0x00000124 (292) Loc: +0x01A8 | offset to field `bob` (string) + +0x0088 | 14 01 00 00 | UOffset32 | 0x00000114 (276) Loc: +0x019C | offset to field `alice` (string) + +0x008C | 0D 00 00 00 | uint32_t | 0x0000000D (13) | table field `just_i32` (Int) + +0x0090 | DC 00 00 00 | UOffset32 | 0x000000DC (220) Loc: +0x016C | offset to field `names` (vector) + +0x0094 | A0 00 00 00 | UOffset32 | 0x000000A0 (160) Loc: +0x0134 | offset to field `points_of_interest` (vector) + +0x0098 | 94 00 00 00 | UOffset32 | 0x00000094 (148) Loc: +0x012C | offset to field `foobars_type` (vector) + +0x009C | 38 00 00 00 | UOffset32 | 0x00000038 (56) Loc: +0x00D4 | offset to field `foobars` (vector) + +0x00A0 | 33 00 00 00 | UOffset32 | 0x00000033 (51) Loc: +0x00D3 | offset to field `measurement` (union of type `Tolerance`) + +0x00A4 | 1C 00 00 00 | UOffset32 | 0x0000001C (28) Loc: +0x00C0 | offset to field `anything` (union of type `Bar`) + +0x00A8 | 04 00 00 00 | UOffset32 | 0x00000004 (4) Loc: +0x00AC | offset to field `charlie` (string) + +string (AnnotatedBinary.Foo.charlie): + +0x00AC | 05 00 00 00 | uint32_t | 0x00000005 (5) | length of string + +0x00B0 | 61 6C 69 63 65 | char[5] | alice + +0x00B5 | 00 | char | 0x00 (0) | string terminator + +padding: + +0x00B6 | 00 00 | uint8_t[2] | .. | padding + +vtable (AnnotatedBinary.Bar): + +0x00B8 | 08 00 | uint16_t | 0x0008 (8) | size of this vtable + +0x00BA | 13 00 | uint16_t | 0x0013 (19) | size of referring table + +0x00BC | 08 00 | VOffset16 | 0x0008 (8) | offset to field `a` (id: 0) + +0x00BE | 04 00 | VOffset16 | 0x0004 (4) | offset to field `b` (id: 1) + +table (AnnotatedBinary.Bar): + +0x00C0 | 08 00 00 00 | SOffset32 | 0x00000008 (8) Loc: +0x00B8 | offset to vtable + +0x00C4 | 00 80 23 44 | float | 0x44238000 (654.000000) | table field `b` (Float) + +0x00C8 | 00 00 00 00 00 10 74 40 | double | 0x4074100000000000 (321.000000) | table field `a` (Double) + +0x00D0 | 00 00 00 | uint8_t[3] | ... | padding + +union (AnnotatedBinary.Tolerance.measurement): + +0x00D3 | 05 | uint8_t | 0x05 (5) | struct field `AnnotatedBinary.Tolerance.width` (UByte) + +vector (AnnotatedBinary.Foo.foobars): + +0x00D4 | 03 00 00 00 | uint32_t | 0x00000003 (3) | length of vector (# items) + +0x00D8 | 34 00 00 00 | UOffset32 | 0x00000034 (52) Loc: +0x010C | offset to union[0] (`Bar`) + +0x00DC | 2C 00 00 00 | ?uint8_t[4] | ,... | WARN: nothing refers to this region. + +0x00E0 | 04 00 00 00 | UOffset32 | 0x00000004 (4) Loc: +0x00E4 | offset to union[2] (`Bar`) + +table (AnnotatedBinary.Bar): + +0x00E4 | D2 FE FF FF | SOffset32 | 0xFFFFFED2 (-302) Loc: +0x0212 | offset to vtable + +0x00E8 | 00 80 23 44 | float | 0x44238000 (654.000000) | table field `b` (Float) + +0x00EC | 10 00 00 00 | UOffset32 | 0x00000010 (16) Loc: +0x00FC | offset to field `c` (table) + +0x00F0 | 00 00 00 00 00 D8 8E 40 | double | 0x408ED80000000000 (987.000000) | table field `a` (Double) + +0x00F8 | 00 00 00 00 | uint8_t[4] | .... | padding + +table (AnnotatedBinary.Baz): + +0x00FC | 6A FE FF FF | SOffset32 | 0xFFFFFE6A (-406) Loc: +0x0292 | offset to vtable + +0x0100 | 00 00 00 | uint8_t[3] | ... | padding + +0x0103 | 03 | uint8_t | 0x03 (3) | table field `meal` (Byte) + +unknown (no known references): + +0x0104 | 04 00 04 00 04 00 00 00 | ?uint8_t[8] | ........ | WARN: nothing refers to this section. + +table (AnnotatedBinary.Bar): + +0x010C | FA FE FF FF | SOffset32 | 0xFFFFFEFA (-262) Loc: +0x0212 | offset to vtable + +0x0110 | 00 00 E4 43 | float | 0x43E40000 (456.000000) | table field `b` (Float) + +0x0114 | 10 00 00 00 | UOffset32 | 0x00000010 (16) Loc: +0x0124 | offset to field `c` (table) + +0x0118 | 00 00 00 00 00 C0 5E 40 | double | 0x405EC00000000000 (123.000000) | table field `a` (Double) + +0x0120 | 00 00 00 00 | uint8_t[4] | .... | padding + +table (AnnotatedBinary.Baz): + +0x0124 | 92 FE FF FF | SOffset32 | 0xFFFFFE92 (-366) Loc: +0x0292 | offset to vtable + +0x0128 | 00 00 00 | uint8_t[3] | ... | padding + +0x012B | 01 | uint8_t | 0x01 (1) | table field `meal` (Byte) + +vector (AnnotatedBinary.Foo.foobars_type): + +0x012C | 03 00 00 00 | uint32_t | 0x00000003 (3) | length of vector (# items) + +0x0130 | 01 | UType8 | 0x01 (1) | value[0] + +0x0131 | FF | UType8 | 0xFF (255) | ERROR: value[1]. Invalid union type value. + +0x0132 | 01 | UType8 | 0x01 (1) | value[2] + +vector (AnnotatedBinary.Foo.points_of_interest): + +0x0134 | 03 00 00 00 | uint32_t | 0x00000003 (3) | length of vector (# items) + +0x0138 | 33 33 33 33 33 A3 45 40 | double | 0x4045A33333333333 (43.275000) | struct field `AnnotatedBinary.Location.latitude` (Double) + +0x0140 | 7E 57 04 FF 5B 87 53 C0 | double | 0xC053875BFF04577E (-78.114990) | struct field `AnnotatedBinary.Location.longitude` (Double) + +0x0148 | 8D F0 F6 20 04 B6 42 40 | double | 0x4042B60420F6F08D (37.422001) | struct field `AnnotatedBinary.Location.latitude` (Double) + +0x0150 | 9F 77 63 41 61 85 5E C0 | double | 0xC05E85614163779F (-122.084061) | struct field `AnnotatedBinary.Location.longitude` (Double) + +0x0158 | 8F 35 23 83 DC 35 4B C0 | double | 0xC04B35DC8323358F (-54.420792) | struct field `AnnotatedBinary.Location.latitude` (Double) + +0x0160 | F6 97 DD 93 87 C5 0A 40 | double | 0x400AC58793DD97F6 (3.346450) | struct field `AnnotatedBinary.Location.longitude` (Double) + +padding: + +0x0168 | 00 00 00 00 | uint8_t[4] | .... | padding + +vector (AnnotatedBinary.Foo.names): + +0x016C | 03 00 00 00 | uint32_t | 0x00000003 (3) | length of vector (# items) + +0x0170 | 20 00 00 00 | UOffset32 | 0x00000020 (32) Loc: +0x0190 | offset to string[0] + +0x0174 | 14 00 00 00 | UOffset32 | 0x00000014 (20) Loc: +0x0188 | offset to string[1] + +0x0178 | 04 00 00 00 | UOffset32 | 0x00000004 (4) Loc: +0x017C | offset to string[2] + +string (AnnotatedBinary.Foo.names): + +0x017C | 07 00 00 00 | uint32_t | 0x00000007 (7) | length of string + +0x0180 | 63 68 61 72 6C 69 65 | char[7] | charlie + +0x0187 | 00 | char | 0x00 (0) | string terminator + +string (AnnotatedBinary.Foo.names): + +0x0188 | 03 00 00 00 | uint32_t | 0x00000003 (3) | length of string + +0x018C | 62 6F 62 | char[3] | bob + +0x018F | 00 | char | 0x00 (0) | string terminator + +string (AnnotatedBinary.Foo.names): + +0x0190 | 05 00 00 00 | uint32_t | 0x00000005 (5) | length of string + +0x0194 | 61 6C 69 63 65 | char[5] | alice + +0x0199 | 00 | char | 0x00 (0) | string terminator + +padding: + +0x019A | 00 00 | uint8_t[2] | .. | padding + +string (AnnotatedBinary.Foo.alice): + +0x019C | 07 00 00 00 | uint32_t | 0x00000007 (7) | length of string + +0x01A0 | 63 68 61 72 6C 69 65 | char[7] | charlie + +0x01A7 | 00 | char | 0x00 (0) | string terminator + +string (AnnotatedBinary.Foo.bob): + +0x01A8 | 07 00 00 00 | uint32_t | 0x00000007 (7) | length of string + +0x01AC | 63 68 61 72 6C 69 65 | char[7] | charlie + +0x01B3 | 00 | char | 0x00 (0) | string terminator + +vector (AnnotatedBinary.Foo.accounts): + +0x01B4 | 09 00 00 00 | uint32_t | 0x00000009 (9) | length of vector (# items) + +0x01B8 | 09 00 | uint16_t | 0x0009 (9) | value[0] + +0x01BA | 08 00 | uint16_t | 0x0008 (8) | value[1] + +0x01BC | 07 00 | uint16_t | 0x0007 (7) | value[2] + +0x01BE | 01 00 | uint16_t | 0x0001 (1) | value[3] + +0x01C0 | 02 00 | uint16_t | 0x0002 (2) | value[4] + +0x01C2 | 03 00 | uint16_t | 0x0003 (3) | value[5] + +0x01C4 | 06 00 | uint16_t | 0x0006 (6) | value[6] + +0x01C6 | 05 00 | uint16_t | 0x0005 (5) | value[7] + +0x01C8 | 04 00 | uint16_t | 0x0004 (4) | value[8] + +padding: + +0x01CA | 00 00 | uint8_t[2] | .. | padding + +table (AnnotatedBinary.Baz): + +0x01CC | 3A FF FF FF | SOffset32 | 0xFFFFFF3A (-198) Loc: +0x0292 | offset to vtable + +0x01D0 | 00 00 00 | uint8_t[3] | ... | padding + +0x01D3 | 03 | uint8_t | 0x03 (3) | table field `meal` (Byte) + +vector (AnnotatedBinary.Foo.bars): + +0x01D4 | 02 00 00 00 | uint32_t | 0x00000002 (2) | length of vector (# items) + +0x01D8 | 44 00 00 00 | UOffset32 | 0x00000044 (68) Loc: +0x021C | offset to table[0] + +0x01DC | 10 00 00 00 | UOffset32 | 0x00000010 (16) Loc: +0x01EC | offset to table[1] + +padding: + +0x01E0 | 00 00 | uint8_t[2] | .. | padding + +vtable (AnnotatedBinary.Bar): + +0x01E2 | 0A 00 | uint16_t | 0x000A (10) | size of this vtable + +0x01E4 | 1A 00 | uint16_t | 0x001A (26) | size of referring table + +0x01E6 | 0C 00 | VOffset16 | 0x000C (12) | offset to field `a` (id: 0) + +0x01E8 | 04 00 | VOffset16 | 0x0004 (4) | offset to field `b` (id: 1) + +0x01EA | 08 00 | VOffset16 | 0x0008 (8) | offset to field `c` (id: 2) + +table (AnnotatedBinary.Bar): + +0x01EC | 0A 00 00 00 | SOffset32 | 0x0000000A (10) Loc: +0x01E2 | offset to vtable + +0x01F0 | 00 80 23 44 | float | 0x44238000 (654.000000) | table field `b` (Float) + +0x01F4 | 18 00 00 00 | UOffset32 | 0x00000018 (24) Loc: +0x020C | offset to field `c` (table) + +0x01F8 | 00 00 00 00 00 D8 8E 40 | double | 0x408ED80000000000 (987.000000) | table field `a` (Double) + +0x0200 | 00 00 00 00 00 00 | uint8_t[6] | ...... | padding + +vtable (AnnotatedBinary.Baz): + +0x0206 | 06 00 | uint16_t | 0x0006 (6) | size of this vtable + +0x0208 | 06 00 | uint16_t | 0x0006 (6) | size of referring table + +0x020A | 05 00 | VOffset16 | 0x0005 (5) | offset to field `meal` (id: 0) + +table (AnnotatedBinary.Baz): + +0x020C | 06 00 00 00 | SOffset32 | 0x00000006 (6) Loc: +0x0206 | offset to vtable + +0x0210 | 00 | uint8_t[1] | . | padding + +0x0211 | 03 | uint8_t | 0x03 (3) | table field `meal` (Byte) + +vtable (AnnotatedBinary.Bar): + +0x0212 | 0A 00 | uint16_t | 0x000A (10) | size of this vtable + +0x0214 | 18 00 | uint16_t | 0x0018 (24) | size of referring table + +0x0216 | 0C 00 | VOffset16 | 0x000C (12) | offset to field `a` (id: 0) + +0x0218 | 04 00 | VOffset16 | 0x0004 (4) | offset to field `b` (id: 1) + +0x021A | 08 00 | VOffset16 | 0x0008 (8) | offset to field `c` (id: 2) + +table (AnnotatedBinary.Bar): + +0x021C | 0A 00 00 00 | SOffset32 | 0x0000000A (10) Loc: +0x0212 | offset to vtable + +0x0220 | 00 00 E4 43 | float | 0x43E40000 (456.000000) | table field `b` (Float) + +0x0224 | 10 00 00 00 | UOffset32 | 0x00000010 (16) Loc: +0x0234 | offset to field `c` (table) + +0x0228 | 00 00 00 00 00 C0 5E 40 | double | 0x405EC00000000000 (123.000000) | table field `a` (Double) + +0x0230 | 00 00 00 00 | uint8_t[4] | .... | padding + +table (AnnotatedBinary.Baz): + +0x0234 | A2 FF FF FF | SOffset32 | 0xFFFFFFA2 (-94) Loc: +0x0292 | offset to vtable + +0x0238 | 00 00 00 | uint8_t[3] | ... | padding + +0x023B | 01 | uint8_t | 0x01 (1) | table field `meal` (Byte) + +string (AnnotatedBinary.Foo.name): + +0x023C | 2F 00 00 00 | uint32_t | 0x0000002F (47) | length of string + +0x0240 | 54 68 69 73 20 69 73 20 | char[47] | This is + +0x0248 | 61 20 6C 6F 6E 67 20 73 | | a long s + +0x0250 | 74 72 69 6E 67 20 74 6F | | tring to + +0x0258 | 20 73 68 6F 77 20 68 6F | | show ho + +0x0260 | 77 20 69 74 20 62 72 65 | | w it bre + +0x0268 | 61 6B 73 20 75 70 2E | | aks up. + +0x026F | 00 | char | 0x00 (0) | string terminator + +padding: + +0x0270 | 00 00 | uint8_t[2] | .. | padding + +vtable (AnnotatedBinary.Bar): + +0x0272 | 0A 00 | uint16_t | 0x000A (10) | size of this vtable + +0x0274 | 16 00 | uint16_t | 0x0016 (22) | size of referring table + +0x0276 | 0C 00 | VOffset16 | 0x000C (12) | offset to field `a` (id: 0) + +0x0278 | 04 00 | VOffset16 | 0x0004 (4) | offset to field `b` (id: 1) + +0x027A | 08 00 | VOffset16 | 0x0008 (8) | offset to field `c` (id: 2) + +table (AnnotatedBinary.Bar): + +0x027C | 0A 00 00 00 | SOffset32 | 0x0000000A (10) Loc: +0x0272 | offset to vtable + +0x0280 | 65 20 71 49 | float | 0x49712065 (987654.312500) | table field `b` (Float) + +0x0284 | 14 00 00 00 | UOffset32 | 0x00000014 (20) Loc: +0x0298 | offset to field `c` (table) + +0x0288 | C9 76 BE 9F 0C 24 FE 40 | double | 0x40FE240C9FBE76C9 (123456.789000) | table field `a` (Double) + +0x0290 | 00 00 | uint8_t[2] | .. | padding + +vtable (AnnotatedBinary.Baz): + +0x0292 | 06 00 | uint16_t | 0x0006 (6) | size of this vtable + +0x0294 | 08 00 | uint16_t | 0x0008 (8) | size of referring table + +0x0296 | 07 00 | VOffset16 | 0x0007 (7) | offset to field `meal` (id: 0) + +table (AnnotatedBinary.Baz): + +0x0298 | 06 00 00 00 | SOffset32 | 0x00000006 (6) Loc: +0x0292 | offset to vtable + +0x029C | 00 00 00 | uint8_t[3] | ... | padding + +0x029F | 01 | uint8_t | 0x01 (1) | table field `meal` (Byte) diff --git a/tests/annotated_binary/tests/invalid_vector_union_type_value.bin b/tests/annotated_binary/tests/invalid_vector_union_type_value.bin new file mode 100644 index 0000000000000000000000000000000000000000..8725971fd1301cfdef90f29a587ab049ef38f978 GIT binary patch literal 672 zcmZXR&nrYx6vw~!>a(YRV+Z;uZ@Fp^TC&-Y|*?MNuSg#$+CoVP=?}lw^fMSrY$) zrDmhpT3N932UuBHc)sU7Y2@@i@4S2NIp^K;y$JyE$;l~T02$PyhU;2H5JeAS2%{f^ zu#sRC7{vspF^hRvSVSF`{pboSeN%>^)RPHx7=U7kjvc}5z(?to5yAsE7s)h8m^i@x5X&$?-UFPTgJnXz)e@;l7BFek5} z$_6W|Stb1jykH*DJwbvwEVS?zL@Buk(VSp?E z#w}<*j?U&bR&}A6cj<~bUC880T5yXxnNK_G1--r5#R>~e75&qCYfSWb+_}4~Z~wC8 LEHasY7Rvn%uH$QC literal 0 HcmV?d00001 diff --git a/tests/annotated_binary/tests/invalid_vector_unions_cut_short.afb b/tests/annotated_binary/tests/invalid_vector_unions_cut_short.afb new file mode 100644 index 000000000..83e873d90 --- /dev/null +++ b/tests/annotated_binary/tests/invalid_vector_unions_cut_short.afb @@ -0,0 +1,209 @@ +// Annotated Flatbuffer Binary +// +// Schema file: annotated_binary.fbs +// Binary file: tests/invalid_vector_unions_cut_short.bin + +header: + +0x0000 | 44 00 00 00 | UOffset32 | 0x00000044 (68) Loc: +0x0044 | offset to root table `AnnotatedBinary.Foo` + +0x0004 | 41 4E 4E 4F | char[4] | ANNO | File Identifier + +padding: + +0x0008 | 00 00 | uint8_t[2] | .. | padding + +vtable (AnnotatedBinary.Foo): + +0x000A | 3A 00 | uint16_t | 0x003A (58) | size of this vtable + +0x000C | 68 00 | uint16_t | 0x0068 (104) | size of referring table + +0x000E | 0C 00 | VOffset16 | 0x000C (12) | offset to field `counter` (id: 0) + +0x0010 | 07 00 | VOffset16 | 0x0007 (7) | offset to field `healthy` (id: 1) + +0x0012 | 00 00 | VOffset16 | 0x0000 (0) | offset to field `level` (id: 2) (Long) + +0x0014 | 08 00 | VOffset16 | 0x0008 (8) | offset to field `meal` (id: 3) + +0x0016 | 10 00 | VOffset16 | 0x0010 (16) | offset to field `bar` (id: 4) + +0x0018 | 14 00 | VOffset16 | 0x0014 (20) | offset to field `home` (id: 5) + +0x001A | 30 00 | VOffset16 | 0x0030 (48) | offset to field `name` (id: 6) + +0x001C | 34 00 | VOffset16 | 0x0034 (52) | offset to field `bars` (id: 7) + +0x001E | 09 00 | VOffset16 | 0x0009 (9) | offset to field `bar_baz_type` (id: 8) + +0x0020 | 38 00 | VOffset16 | 0x0038 (56) | offset to field `bar_baz` (id: 9) + +0x0022 | 3C 00 | VOffset16 | 0x003C (60) | offset to field `accounts` (id: 10) + +0x0024 | 40 00 | VOffset16 | 0x0040 (64) | offset to field `bob` (id: 11) + +0x0026 | 44 00 | VOffset16 | 0x0044 (68) | offset to field `alice` (id: 12) + +0x0028 | 00 00 | VOffset16 | 0x0000 (0) | offset to field `maybe_i32` (id: 13) (Int) + +0x002A | 00 00 | VOffset16 | 0x0000 (0) | offset to field `default_i32` (id: 14) (Int) + +0x002C | 48 00 | VOffset16 | 0x0048 (72) | offset to field `just_i32` (id: 15) + +0x002E | 4C 00 | VOffset16 | 0x004C (76) | offset to field `names` (id: 16) + +0x0030 | 50 00 | VOffset16 | 0x0050 (80) | offset to field `points_of_interest` (id: 17) + +0x0032 | 54 00 | VOffset16 | 0x0054 (84) | offset to field `foobars_type` (id: 18) + +0x0034 | 58 00 | VOffset16 | 0x0058 (88) | offset to field `foobars` (id: 19) + +0x0036 | 0A 00 | VOffset16 | 0x000A (10) | offset to field `measurement_type` (id: 20) + +0x0038 | 5C 00 | VOffset16 | 0x005C (92) | offset to field `measurement` (id: 21) + +0x003A | 0B 00 | VOffset16 | 0x000B (11) | offset to field `anything_type` (id: 22) + +0x003C | 60 00 | VOffset16 | 0x0060 (96) | offset to field `anything` (id: 23) + +0x003E | 00 00 | VOffset16 | 0x0000 (0) | offset to field `temperature` (id: 24) (Float) + +0x0040 | 00 00 | VOffset16 | 0x0000 (0) | offset to field `teetotaler` (id: 25) (Obj) + +0x0042 | 64 00 | VOffset16 | 0x0064 (100) | offset to field `charlie` (id: 26) + +root_table (AnnotatedBinary.Foo): + +0x0044 | 3A 00 00 00 | SOffset32 | 0x0000003A (58) Loc: +0x000A | offset to vtable + +0x0048 | 00 00 00 | uint8_t[3] | ... | padding + +0x004B | 01 | uint8_t | 0x01 (1) | table field `healthy` (Bool) + +0x004C | 02 | uint8_t | 0x02 (2) | table field `meal` (Byte) + +0x004D | 02 | UType8 | 0x02 (2) | table field `bar_baz_type` (UType) + +0x004E | 01 | UType8 | 0x01 (1) | table field `measurement_type` (UType) + +0x004F | 01 | UType8 | 0x01 (1) | table field `anything_type` (UType) + +0x0050 | D2 04 00 00 | uint32_t | 0x000004D2 (1234) | table field `counter` (Int) + +0x0054 | 28 02 00 00 | UOffset32 | 0x00000228 (552) Loc: +0x027C | ERROR: offset to field `bar`. Location is outside the binary. + +0x0058 | 01 00 00 00 | uint32_t | 0x00000001 (1) | struct field `AnnotatedBinary.Building.floors` (Int) + +0x005C | 02 00 00 00 | uint32_t | 0x00000002 (2) | struct field `AnnotatedBinary.Building.doors` (Int) + +0x0060 | 0C 00 00 00 | uint32_t | 0x0000000C (12) | struct field `AnnotatedBinary.Building.windows` (Int) + +0x0064 | 0A 00 00 00 | uint32_t | 0x0000000A (10) | array field `AnnotatedBinary.Dimension.values[0]` (Int) + +0x0068 | 0C 00 00 00 | uint32_t | 0x0000000C (12) | array field `AnnotatedBinary.Dimension.values[1]` (Int) + +0x006C | 14 00 00 00 | uint32_t | 0x00000014 (20) | array field `AnnotatedBinary.Dimension.values[2]` (Int) + +0x0070 | 01 | uint8_t | 0x01 (1) | struct field `AnnotatedBinary.Tolerance.width` (UByte) + +0x0071 | 02 | uint8_t | 0x02 (2) | struct field `AnnotatedBinary.Tolerance.width` (UByte) + +0x0072 | 03 | uint8_t | 0x03 (3) | struct field `AnnotatedBinary.Tolerance.width` (UByte) + +0x0073 | 00 | uint8_t[1] | . | padding + +0x0074 | C8 01 00 00 | UOffset32 | 0x000001C8 (456) Loc: +0x023C | ERROR: offset to field `name`. Location is outside the binary. + +0x0078 | 5C 01 00 00 | UOffset32 | 0x0000015C (348) Loc: +0x01D4 | offset to field `bars` (vector) + +0x007C | 50 01 00 00 | UOffset32 | 0x00000150 (336) Loc: +0x01CC | offset to field `bar_baz` (union of type `Baz`) + +0x0080 | 34 01 00 00 | UOffset32 | 0x00000134 (308) Loc: +0x01B4 | offset to field `accounts` (vector) + +0x0084 | 24 01 00 00 | UOffset32 | 0x00000124 (292) Loc: +0x01A8 | offset to field `bob` (string) + +0x0088 | 14 01 00 00 | UOffset32 | 0x00000114 (276) Loc: +0x019C | offset to field `alice` (string) + +0x008C | 0D 00 00 00 | uint32_t | 0x0000000D (13) | table field `just_i32` (Int) + +0x0090 | DC 00 00 00 | UOffset32 | 0x000000DC (220) Loc: +0x016C | offset to field `names` (vector) + +0x0094 | A0 00 00 00 | UOffset32 | 0x000000A0 (160) Loc: +0x0134 | offset to field `points_of_interest` (vector) + +0x0098 | 94 00 00 00 | UOffset32 | 0x00000094 (148) Loc: +0x012C | offset to field `foobars_type` (vector) + +0x009C | 38 00 00 00 | UOffset32 | 0x00000038 (56) Loc: +0x00D4 | offset to field `foobars` (vector) + +0x00A0 | 33 00 00 00 | UOffset32 | 0x00000033 (51) Loc: +0x00D3 | offset to field `measurement` (union of type `Tolerance`) + +0x00A4 | 1C 00 00 00 | UOffset32 | 0x0000001C (28) Loc: +0x00C0 | offset to field `anything` (union of type `Bar`) + +0x00A8 | 04 00 00 00 | UOffset32 | 0x00000004 (4) Loc: +0x00AC | offset to field `charlie` (string) + +string (AnnotatedBinary.Foo.charlie): + +0x00AC | 05 00 00 00 | uint32_t | 0x00000005 (5) | length of string + +0x00B0 | 61 6C 69 63 65 | char[5] | alice + +0x00B5 | 00 | char | 0x00 (0) | string terminator + +padding: + +0x00B6 | 00 00 | uint8_t[2] | .. | padding + +vtable (AnnotatedBinary.Bar): + +0x00B8 | 08 00 | uint16_t | 0x0008 (8) | size of this vtable + +0x00BA | 13 00 | uint16_t | 0x0013 (19) | size of referring table + +0x00BC | 08 00 | VOffset16 | 0x0008 (8) | offset to field `a` (id: 0) + +0x00BE | 04 00 | VOffset16 | 0x0004 (4) | offset to field `b` (id: 1) + +table (AnnotatedBinary.Bar): + +0x00C0 | 08 00 00 00 | SOffset32 | 0x00000008 (8) Loc: +0x00B8 | offset to vtable + +0x00C4 | 00 80 23 44 | float | 0x44238000 (654.000000) | table field `b` (Float) + +0x00C8 | 00 00 00 00 00 10 74 40 | double | 0x4074100000000000 (321.000000) | table field `a` (Double) + +0x00D0 | 00 00 00 | uint8_t[3] | ... | padding + +union (AnnotatedBinary.Tolerance.measurement): + +0x00D3 | 05 | uint8_t | 0x05 (5) | struct field `AnnotatedBinary.Tolerance.width` (UByte) + +vector (AnnotatedBinary.Foo.foobars): + +0x00D4 | 03 00 00 00 | uint32_t | 0x00000003 (3) | length of vector (# items) + +0x00D8 | 34 00 00 00 | UOffset32 | 0x00000034 (52) Loc: +0x010C | offset to union[0] (`Bar`) + +0x00DC | 2C 00 00 00 | UOffset32 | 0x0000002C (44) Loc: +0x0108 | offset to union[1] (`Baz`) + +0x00E0 | 04 00 00 00 | UOffset32 | 0x00000004 (4) Loc: +0x00E4 | offset to union[2] (`Bar`) + +table (AnnotatedBinary.Bar): + +0x00E4 | D2 FE FF FF | SOffset32 | 0xFFFFFED2 (-302) Loc: +0x0212 | ERROR: offset to vtable. Invalid offset, points to outside the binary. + +unknown (no known references): + +0x00E8 | 00 80 23 44 10 00 00 00 | ?uint8_t[28] | ..#D.... | WARN: nothing refers to this section. + +0x00F0 | 00 00 00 00 00 D8 8E 40 | | .......@ + +0x00F8 | 00 00 00 00 6A FE FF FF | | ....j... + +0x0100 | 00 00 00 03 | | .... + +vtable (AnnotatedBinary.Baz): + +0x0104 | 04 00 | uint16_t | 0x0004 (4) | size of this vtable + +0x0106 | 04 00 | uint16_t | 0x0004 (4) | size of referring table + +table (AnnotatedBinary.Baz): + +0x0108 | 04 00 00 00 | SOffset32 | 0x00000004 (4) Loc: +0x0104 | offset to vtable + +table (AnnotatedBinary.Bar): + +0x010C | FA FE FF FF | SOffset32 | 0xFFFFFEFA (-262) Loc: +0x0212 | ERROR: offset to vtable. Invalid offset, points to outside the binary. + +unknown (no known references): + +0x0110 | 00 00 E4 43 10 00 00 00 | ?uint8_t[28] | ...C.... | WARN: nothing refers to this section. + +0x0118 | 00 00 00 00 00 C0 5E 40 | | ......^@ + +0x0120 | 00 00 00 00 92 FE FF FF | | ........ + +0x0128 | 00 00 00 01 | | .... + +vector (AnnotatedBinary.Foo.foobars_type): + +0x012C | 03 00 00 00 | uint32_t | 0x00000003 (3) | length of vector (# items) + +0x0130 | 01 | UType8 | 0x01 (1) | value[0] + +0x0131 | 02 | UType8 | 0x02 (2) | value[1] + +0x0132 | 01 | UType8 | 0x01 (1) | value[2] + +vector (AnnotatedBinary.Foo.points_of_interest): + +0x0134 | 03 00 00 00 | uint32_t | 0x00000003 (3) | length of vector (# items) + +0x0138 | 33 33 33 33 33 A3 45 40 | double | 0x4045A33333333333 (43.275000) | struct field `AnnotatedBinary.Location.latitude` (Double) + +0x0140 | 7E 57 04 FF 5B 87 53 C0 | double | 0xC053875BFF04577E (-78.114990) | struct field `AnnotatedBinary.Location.longitude` (Double) + +0x0148 | 8D F0 F6 20 04 B6 42 40 | double | 0x4042B60420F6F08D (37.422001) | struct field `AnnotatedBinary.Location.latitude` (Double) + +0x0150 | 9F 77 63 41 61 85 5E C0 | double | 0xC05E85614163779F (-122.084061) | struct field `AnnotatedBinary.Location.longitude` (Double) + +0x0158 | 8F 35 23 83 DC 35 4B C0 | double | 0xC04B35DC8323358F (-54.420792) | struct field `AnnotatedBinary.Location.latitude` (Double) + +0x0160 | F6 97 DD 93 87 C5 0A 40 | double | 0x400AC58793DD97F6 (3.346450) | struct field `AnnotatedBinary.Location.longitude` (Double) + +padding: + +0x0168 | 00 00 00 00 | uint8_t[4] | .... | padding + +vector (AnnotatedBinary.Foo.names): + +0x016C | 03 00 00 00 | uint32_t | 0x00000003 (3) | length of vector (# items) + +0x0170 | 20 00 00 00 | UOffset32 | 0x00000020 (32) Loc: +0x0190 | offset to string[0] + +0x0174 | 14 00 00 00 | UOffset32 | 0x00000014 (20) Loc: +0x0188 | offset to string[1] + +0x0178 | 04 00 00 00 | UOffset32 | 0x00000004 (4) Loc: +0x017C | offset to string[2] + +string (AnnotatedBinary.Foo.names): + +0x017C | 07 00 00 00 | uint32_t | 0x00000007 (7) | length of string + +0x0180 | 63 68 61 72 6C 69 65 | char[7] | charlie + +0x0187 | 00 | char | 0x00 (0) | string terminator + +string (AnnotatedBinary.Foo.names): + +0x0188 | 03 00 00 00 | uint32_t | 0x00000003 (3) | length of string + +0x018C | 62 6F 62 | char[3] | bob + +0x018F | 00 | char | 0x00 (0) | string terminator + +string (AnnotatedBinary.Foo.names): + +0x0190 | 05 00 00 00 | uint32_t | 0x00000005 (5) | length of string + +0x0194 | 61 6C 69 63 65 | char[5] | alice + +0x0199 | 00 | char | 0x00 (0) | string terminator + +padding: + +0x019A | 00 00 | uint8_t[2] | .. | padding + +string (AnnotatedBinary.Foo.alice): + +0x019C | 07 00 00 00 | uint32_t | 0x00000007 (7) | length of string + +0x01A0 | 63 68 61 72 6C 69 65 | char[7] | charlie + +0x01A7 | 00 | char | 0x00 (0) | string terminator + +string (AnnotatedBinary.Foo.bob): + +0x01A8 | 07 00 00 00 | uint32_t | 0x00000007 (7) | length of string + +0x01AC | 63 68 61 72 6C 69 65 | char[7] | charlie + +0x01B3 | 00 | char | 0x00 (0) | string terminator + +vector (AnnotatedBinary.Foo.accounts): + +0x01B4 | 09 00 00 00 | uint32_t | 0x00000009 (9) | length of vector (# items) + +0x01B8 | 09 00 | uint16_t | 0x0009 (9) | value[0] + +0x01BA | 08 00 | uint16_t | 0x0008 (8) | value[1] + +0x01BC | 07 00 | uint16_t | 0x0007 (7) | value[2] + +0x01BE | 01 00 | uint16_t | 0x0001 (1) | value[3] + +0x01C0 | 02 00 | uint16_t | 0x0002 (2) | value[4] + +0x01C2 | 03 00 | uint16_t | 0x0003 (3) | value[5] + +0x01C4 | 06 00 | uint16_t | 0x0006 (6) | value[6] + +0x01C6 | 05 00 | uint16_t | 0x0005 (5) | value[7] + +0x01C8 | 04 00 | uint16_t | 0x0004 (4) | value[8] + +padding: + +0x01CA | 00 00 | uint8_t[2] | .. | padding + +table (AnnotatedBinary.Baz): + +0x01CC | 3A FF FF FF | SOffset32 | 0xFFFFFF3A (-198) Loc: +0x0292 | ERROR: offset to vtable. Invalid offset, points to outside the binary. + +unknown (no known references): + +0x01D0 | 00 00 00 03 | ?uint8_t[4] | .... | could be a corrupted padding region (non zero) due to the length < 8 bytes. + +vector (AnnotatedBinary.Foo.bars): + +0x01D4 | 02 00 00 00 | uint32_t | 0x00000002 (2) | length of vector (# items) + +0x01D8 | 44 00 00 00 | UOffset32 | 0x00000044 (68) Loc: +0x021C | ERROR: offset to table[0]. Invalid offset, points to outside the binary. + +0x01DC | 10 00 | ?uint8_t[2] | .. | ERROR: offset to table[1]. Incomplete binary, expected to read 4 bytes here diff --git a/tests/annotated_binary/tests/invalid_vector_unions_cut_short.bin b/tests/annotated_binary/tests/invalid_vector_unions_cut_short.bin new file mode 100644 index 0000000000000000000000000000000000000000..2823d83ef925f10fd6f46340c780417c91938717 GIT binary patch literal 478 zcmY+AF-yZx6ot=AQrlF8fE^tQb#QPHnnEcKuNpy6YC%E4QcPo^m4YCGn+PJER8YZD z!T;c#MR4xqP&a>oQwIm*xd}+U@a5#)d(TbY^#D|BwN0Rc4yKUiIRghdEW(A2GM1p> zF$=6=19fa;7g;ngiTyZxKxZ7vFq9ftz`Ow{rYM{Ub|;#nD#OGZiw#mIE}0`aGR^vs zJdt}+CPgw!I2I}5_qsuwn!yaQ2;;nv{GfB9c}kglxMYEdZ}1aE(&O+wj`wRVdMJ6o zwAdwm-|_i#<*zSnYNm0U^eLIE3_NUKyAC@3aj)BsYptW!zdMfC$KP%GY~DQ0EgN)B&?WOK MQF0&IyGI=S0>Jr7NB{r; literal 0 HcmV?d00001 diff --git a/tests/annotated_binary/tests/invalid_vtable_field_offset.afb b/tests/annotated_binary/tests/invalid_vtable_field_offset.afb new file mode 100644 index 000000000..977010d80 --- /dev/null +++ b/tests/annotated_binary/tests/invalid_vtable_field_offset.afb @@ -0,0 +1,286 @@ +// Annotated Flatbuffer Binary +// +// Schema file: annotated_binary.fbs +// Binary file: tests/invalid_vtable_field_offset.bin + +header: + +0x0000 | 44 00 00 00 | UOffset32 | 0x00000044 (68) Loc: +0x0044 | offset to root table `AnnotatedBinary.Foo` + +0x0004 | 41 4E 4E 4F | char[4] | ANNO | File Identifier + +padding: + +0x0008 | 00 00 | uint8_t[2] | .. | padding + +vtable (AnnotatedBinary.Foo): + +0x000A | 3A 00 | uint16_t | 0x003A (58) | size of this vtable + +0x000C | 68 00 | uint16_t | 0x0068 (104) | size of referring table + +0x000E | 0C 00 | VOffset16 | 0x000C (12) | offset to field `counter` (id: 0) + +0x0010 | 07 00 | VOffset16 | 0x0007 (7) | offset to field `healthy` (id: 1) + +0x0012 | 00 00 | VOffset16 | 0x0000 (0) | offset to field `level` (id: 2) (Long) + +0x0014 | 08 00 | VOffset16 | 0x0008 (8) | offset to field `meal` (id: 3) + +0x0016 | FF FF | VOffset16 | 0xFFFF (65535) | ERROR: offset to field `bar` (id: 4). Invalid offset, points to outside the binary. + +0x0018 | 14 00 | VOffset16 | 0x0014 (20) | offset to field `home` (id: 5) + +0x001A | 30 00 | VOffset16 | 0x0030 (48) | offset to field `name` (id: 6) + +0x001C | 34 00 | VOffset16 | 0x0034 (52) | offset to field `bars` (id: 7) + +0x001E | 09 00 | VOffset16 | 0x0009 (9) | offset to field `bar_baz_type` (id: 8) + +0x0020 | 38 00 | VOffset16 | 0x0038 (56) | offset to field `bar_baz` (id: 9) + +0x0022 | 3C 00 | VOffset16 | 0x003C (60) | offset to field `accounts` (id: 10) + +0x0024 | 40 00 | VOffset16 | 0x0040 (64) | offset to field `bob` (id: 11) + +0x0026 | 44 00 | VOffset16 | 0x0044 (68) | offset to field `alice` (id: 12) + +0x0028 | 00 00 | VOffset16 | 0x0000 (0) | offset to field `maybe_i32` (id: 13) (Int) + +0x002A | 00 00 | VOffset16 | 0x0000 (0) | offset to field `default_i32` (id: 14) (Int) + +0x002C | 48 00 | VOffset16 | 0x0048 (72) | offset to field `just_i32` (id: 15) + +0x002E | 4C 00 | VOffset16 | 0x004C (76) | offset to field `names` (id: 16) + +0x0030 | 50 00 | VOffset16 | 0x0050 (80) | offset to field `points_of_interest` (id: 17) + +0x0032 | 54 00 | VOffset16 | 0x0054 (84) | offset to field `foobars_type` (id: 18) + +0x0034 | 58 00 | VOffset16 | 0x0058 (88) | offset to field `foobars` (id: 19) + +0x0036 | 0A 00 | VOffset16 | 0x000A (10) | offset to field `measurement_type` (id: 20) + +0x0038 | 5C 00 | VOffset16 | 0x005C (92) | offset to field `measurement` (id: 21) + +0x003A | 0B 00 | VOffset16 | 0x000B (11) | offset to field `anything_type` (id: 22) + +0x003C | 60 00 | VOffset16 | 0x0060 (96) | offset to field `anything` (id: 23) + +0x003E | 00 00 | VOffset16 | 0x0000 (0) | offset to field `temperature` (id: 24) (Float) + +0x0040 | 00 00 | VOffset16 | 0x0000 (0) | offset to field `teetotaler` (id: 25) (Obj) + +0x0042 | 64 00 | VOffset16 | 0x0064 (100) | offset to field `charlie` (id: 26) + +0x0042 | 64 00 | VOffset16 | 0x0064 (100) | offset to unknown field (id: 26) + +root_table (AnnotatedBinary.Foo): + +0x0044 | 3A 00 00 00 | SOffset32 | 0x0000003A (58) Loc: +0x000A | offset to vtable + +0x0048 | 00 00 00 | uint8_t[3] | ... | padding + +0x004B | 01 | uint8_t | 0x01 (1) | table field `healthy` (Bool) + +0x004C | 02 | uint8_t | 0x02 (2) | table field `meal` (Byte) + +0x004D | 02 | UType8 | 0x02 (2) | table field `bar_baz_type` (UType) + +0x004E | 01 | UType8 | 0x01 (1) | table field `measurement_type` (UType) + +0x004F | 01 | UType8 | 0x01 (1) | table field `anything_type` (UType) + +0x0050 | D2 04 00 00 | uint32_t | 0x000004D2 (1234) | table field `counter` (Int) + +0x0054 | 28 02 00 00 | ?uint8_t[4] | (... | WARN: nothing refers to this region. + +0x0058 | 01 00 00 00 | uint32_t | 0x00000001 (1) | struct field `AnnotatedBinary.Building.floors` (Int) + +0x005C | 02 00 00 00 | uint32_t | 0x00000002 (2) | struct field `AnnotatedBinary.Building.doors` (Int) + +0x0060 | 0C 00 00 00 | uint32_t | 0x0000000C (12) | struct field `AnnotatedBinary.Building.windows` (Int) + +0x0064 | 0A 00 00 00 | uint32_t | 0x0000000A (10) | array field `AnnotatedBinary.Dimension.values[0]` (Int) + +0x0068 | 0C 00 00 00 | uint32_t | 0x0000000C (12) | array field `AnnotatedBinary.Dimension.values[1]` (Int) + +0x006C | 14 00 00 00 | uint32_t | 0x00000014 (20) | array field `AnnotatedBinary.Dimension.values[2]` (Int) + +0x0070 | 01 | uint8_t | 0x01 (1) | struct field `AnnotatedBinary.Tolerance.width` (UByte) + +0x0071 | 02 | uint8_t | 0x02 (2) | struct field `AnnotatedBinary.Tolerance.width` (UByte) + +0x0072 | 03 | uint8_t | 0x03 (3) | struct field `AnnotatedBinary.Tolerance.width` (UByte) + +0x0073 | 00 | uint8_t[1] | . | padding + +0x0074 | C8 01 00 00 | UOffset32 | 0x000001C8 (456) Loc: +0x023C | offset to field `name` (string) + +0x0078 | 5C 01 00 00 | UOffset32 | 0x0000015C (348) Loc: +0x01D4 | offset to field `bars` (vector) + +0x007C | 50 01 00 00 | UOffset32 | 0x00000150 (336) Loc: +0x01CC | offset to field `bar_baz` (union of type `Baz`) + +0x0080 | 34 01 00 00 | UOffset32 | 0x00000134 (308) Loc: +0x01B4 | offset to field `accounts` (vector) + +0x0084 | 24 01 00 00 | UOffset32 | 0x00000124 (292) Loc: +0x01A8 | offset to field `bob` (string) + +0x0088 | 14 01 00 00 | UOffset32 | 0x00000114 (276) Loc: +0x019C | offset to field `alice` (string) + +0x008C | 0D 00 00 00 | uint32_t | 0x0000000D (13) | table field `just_i32` (Int) + +0x0090 | DC 00 00 00 | UOffset32 | 0x000000DC (220) Loc: +0x016C | offset to field `names` (vector) + +0x0094 | A0 00 00 00 | UOffset32 | 0x000000A0 (160) Loc: +0x0134 | offset to field `points_of_interest` (vector) + +0x0098 | 94 00 00 00 | UOffset32 | 0x00000094 (148) Loc: +0x012C | offset to field `foobars_type` (vector) + +0x009C | 38 00 00 00 | UOffset32 | 0x00000038 (56) Loc: +0x00D4 | offset to field `foobars` (vector) + +0x00A0 | 33 00 00 00 | UOffset32 | 0x00000033 (51) Loc: +0x00D3 | offset to field `measurement` (union of type `Tolerance`) + +0x00A4 | 1C 00 00 00 | UOffset32 | 0x0000001C (28) Loc: +0x00C0 | offset to field `anything` (union of type `Bar`) + +0x00A8 | 04 00 00 00 | UOffset32 | 0x00000004 (4) Loc: +0x00AC | offset to field `charlie` (string) + +string (AnnotatedBinary.Foo.charlie): + +0x00AC | 05 00 00 00 | uint32_t | 0x00000005 (5) | length of string + +0x00B0 | 61 6C 69 63 65 | char[5] | alice + +0x00B5 | 00 | char | 0x00 (0) | string terminator + +padding: + +0x00B6 | 00 00 | uint8_t[2] | .. | padding + +vtable (AnnotatedBinary.Bar): + +0x00B8 | 08 00 | uint16_t | 0x0008 (8) | size of this vtable + +0x00BA | 13 00 | uint16_t | 0x0013 (19) | size of referring table + +0x00BC | 08 00 | VOffset16 | 0x0008 (8) | offset to field `a` (id: 0) + +0x00BE | 04 00 | VOffset16 | 0x0004 (4) | offset to field `b` (id: 1) + +table (AnnotatedBinary.Bar): + +0x00C0 | 08 00 00 00 | SOffset32 | 0x00000008 (8) Loc: +0x00B8 | offset to vtable + +0x00C4 | 00 80 23 44 | float | 0x44238000 (654.000000) | table field `b` (Float) + +0x00C8 | 00 00 00 00 00 10 74 40 | double | 0x4074100000000000 (321.000000) | table field `a` (Double) + +0x00D0 | 00 00 00 | uint8_t[3] | ... | padding + +union (AnnotatedBinary.Tolerance.measurement): + +0x00D3 | 05 | uint8_t | 0x05 (5) | struct field `AnnotatedBinary.Tolerance.width` (UByte) + +vector (AnnotatedBinary.Foo.foobars): + +0x00D4 | 03 00 00 00 | uint32_t | 0x00000003 (3) | length of vector (# items) + +0x00D8 | 34 00 00 00 | UOffset32 | 0x00000034 (52) Loc: +0x010C | offset to union[0] (`Bar`) + +0x00DC | 2C 00 00 00 | UOffset32 | 0x0000002C (44) Loc: +0x0108 | offset to union[1] (`Baz`) + +0x00E0 | 04 00 00 00 | UOffset32 | 0x00000004 (4) Loc: +0x00E4 | offset to union[2] (`Bar`) + +table (AnnotatedBinary.Bar): + +0x00E4 | D2 FE FF FF | SOffset32 | 0xFFFFFED2 (-302) Loc: +0x0212 | offset to vtable + +0x00E8 | 00 80 23 44 | float | 0x44238000 (654.000000) | table field `b` (Float) + +0x00EC | 10 00 00 00 | UOffset32 | 0x00000010 (16) Loc: +0x00FC | offset to field `c` (table) + +0x00F0 | 00 00 00 00 00 D8 8E 40 | double | 0x408ED80000000000 (987.000000) | table field `a` (Double) + +0x00F8 | 00 00 00 00 | uint8_t[4] | .... | padding + +table (AnnotatedBinary.Baz): + +0x00FC | 6A FE FF FF | SOffset32 | 0xFFFFFE6A (-406) Loc: +0x0292 | offset to vtable + +0x0100 | 00 00 00 | uint8_t[3] | ... | padding + +0x0103 | 03 | uint8_t | 0x03 (3) | table field `meal` (Byte) + +vtable (AnnotatedBinary.Baz): + +0x0104 | 04 00 | uint16_t | 0x0004 (4) | size of this vtable + +0x0106 | 04 00 | uint16_t | 0x0004 (4) | size of referring table + +table (AnnotatedBinary.Baz): + +0x0108 | 04 00 00 00 | SOffset32 | 0x00000004 (4) Loc: +0x0104 | offset to vtable + +table (AnnotatedBinary.Bar): + +0x010C | FA FE FF FF | SOffset32 | 0xFFFFFEFA (-262) Loc: +0x0212 | offset to vtable + +0x0110 | 00 00 E4 43 | float | 0x43E40000 (456.000000) | table field `b` (Float) + +0x0114 | 10 00 00 00 | UOffset32 | 0x00000010 (16) Loc: +0x0124 | offset to field `c` (table) + +0x0118 | 00 00 00 00 00 C0 5E 40 | double | 0x405EC00000000000 (123.000000) | table field `a` (Double) + +0x0120 | 00 00 00 00 | uint8_t[4] | .... | padding + +table (AnnotatedBinary.Baz): + +0x0124 | 92 FE FF FF | SOffset32 | 0xFFFFFE92 (-366) Loc: +0x0292 | offset to vtable + +0x0128 | 00 00 00 | uint8_t[3] | ... | padding + +0x012B | 01 | uint8_t | 0x01 (1) | table field `meal` (Byte) + +vector (AnnotatedBinary.Foo.foobars_type): + +0x012C | 03 00 00 00 | uint32_t | 0x00000003 (3) | length of vector (# items) + +0x0130 | 01 | UType8 | 0x01 (1) | value[0] + +0x0131 | 02 | UType8 | 0x02 (2) | value[1] + +0x0132 | 01 | UType8 | 0x01 (1) | value[2] + +vector (AnnotatedBinary.Foo.points_of_interest): + +0x0134 | 03 00 00 00 | uint32_t | 0x00000003 (3) | length of vector (# items) + +0x0138 | 33 33 33 33 33 A3 45 40 | double | 0x4045A33333333333 (43.275000) | struct field `AnnotatedBinary.Location.latitude` (Double) + +0x0140 | 7E 57 04 FF 5B 87 53 C0 | double | 0xC053875BFF04577E (-78.114990) | struct field `AnnotatedBinary.Location.longitude` (Double) + +0x0148 | 8D F0 F6 20 04 B6 42 40 | double | 0x4042B60420F6F08D (37.422001) | struct field `AnnotatedBinary.Location.latitude` (Double) + +0x0150 | 9F 77 63 41 61 85 5E C0 | double | 0xC05E85614163779F (-122.084061) | struct field `AnnotatedBinary.Location.longitude` (Double) + +0x0158 | 8F 35 23 83 DC 35 4B C0 | double | 0xC04B35DC8323358F (-54.420792) | struct field `AnnotatedBinary.Location.latitude` (Double) + +0x0160 | F6 97 DD 93 87 C5 0A 40 | double | 0x400AC58793DD97F6 (3.346450) | struct field `AnnotatedBinary.Location.longitude` (Double) + +padding: + +0x0168 | 00 00 00 00 | uint8_t[4] | .... | padding + +vector (AnnotatedBinary.Foo.names): + +0x016C | 03 00 00 00 | uint32_t | 0x00000003 (3) | length of vector (# items) + +0x0170 | 20 00 00 00 | UOffset32 | 0x00000020 (32) Loc: +0x0190 | offset to string[0] + +0x0174 | 14 00 00 00 | UOffset32 | 0x00000014 (20) Loc: +0x0188 | offset to string[1] + +0x0178 | 04 00 00 00 | UOffset32 | 0x00000004 (4) Loc: +0x017C | offset to string[2] + +string (AnnotatedBinary.Foo.names): + +0x017C | 07 00 00 00 | uint32_t | 0x00000007 (7) | length of string + +0x0180 | 63 68 61 72 6C 69 65 | char[7] | charlie + +0x0187 | 00 | char | 0x00 (0) | string terminator + +string (AnnotatedBinary.Foo.names): + +0x0188 | 03 00 00 00 | uint32_t | 0x00000003 (3) | length of string + +0x018C | 62 6F 62 | char[3] | bob + +0x018F | 00 | char | 0x00 (0) | string terminator + +string (AnnotatedBinary.Foo.names): + +0x0190 | 05 00 00 00 | uint32_t | 0x00000005 (5) | length of string + +0x0194 | 61 6C 69 63 65 | char[5] | alice + +0x0199 | 00 | char | 0x00 (0) | string terminator + +padding: + +0x019A | 00 00 | uint8_t[2] | .. | padding + +string (AnnotatedBinary.Foo.alice): + +0x019C | 07 00 00 00 | uint32_t | 0x00000007 (7) | length of string + +0x01A0 | 63 68 61 72 6C 69 65 | char[7] | charlie + +0x01A7 | 00 | char | 0x00 (0) | string terminator + +string (AnnotatedBinary.Foo.bob): + +0x01A8 | 07 00 00 00 | uint32_t | 0x00000007 (7) | length of string + +0x01AC | 63 68 61 72 6C 69 65 | char[7] | charlie + +0x01B3 | 00 | char | 0x00 (0) | string terminator + +vector (AnnotatedBinary.Foo.accounts): + +0x01B4 | 09 00 00 00 | uint32_t | 0x00000009 (9) | length of vector (# items) + +0x01B8 | 09 00 | uint16_t | 0x0009 (9) | value[0] + +0x01BA | 08 00 | uint16_t | 0x0008 (8) | value[1] + +0x01BC | 07 00 | uint16_t | 0x0007 (7) | value[2] + +0x01BE | 01 00 | uint16_t | 0x0001 (1) | value[3] + +0x01C0 | 02 00 | uint16_t | 0x0002 (2) | value[4] + +0x01C2 | 03 00 | uint16_t | 0x0003 (3) | value[5] + +0x01C4 | 06 00 | uint16_t | 0x0006 (6) | value[6] + +0x01C6 | 05 00 | uint16_t | 0x0005 (5) | value[7] + +0x01C8 | 04 00 | uint16_t | 0x0004 (4) | value[8] + +padding: + +0x01CA | 00 00 | uint8_t[2] | .. | padding + +table (AnnotatedBinary.Baz): + +0x01CC | 3A FF FF FF | SOffset32 | 0xFFFFFF3A (-198) Loc: +0x0292 | offset to vtable + +0x01D0 | 00 00 00 | uint8_t[3] | ... | padding + +0x01D3 | 03 | uint8_t | 0x03 (3) | table field `meal` (Byte) + +vector (AnnotatedBinary.Foo.bars): + +0x01D4 | 02 00 00 00 | uint32_t | 0x00000002 (2) | length of vector (# items) + +0x01D8 | 44 00 00 00 | UOffset32 | 0x00000044 (68) Loc: +0x021C | offset to table[0] + +0x01DC | 10 00 00 00 | UOffset32 | 0x00000010 (16) Loc: +0x01EC | offset to table[1] + +padding: + +0x01E0 | 00 00 | uint8_t[2] | .. | padding + +vtable (AnnotatedBinary.Bar): + +0x01E2 | 0A 00 | uint16_t | 0x000A (10) | size of this vtable + +0x01E4 | 1A 00 | uint16_t | 0x001A (26) | size of referring table + +0x01E6 | 0C 00 | VOffset16 | 0x000C (12) | offset to field `a` (id: 0) + +0x01E8 | 04 00 | VOffset16 | 0x0004 (4) | offset to field `b` (id: 1) + +0x01EA | 08 00 | VOffset16 | 0x0008 (8) | offset to field `c` (id: 2) + +table (AnnotatedBinary.Bar): + +0x01EC | 0A 00 00 00 | SOffset32 | 0x0000000A (10) Loc: +0x01E2 | offset to vtable + +0x01F0 | 00 80 23 44 | float | 0x44238000 (654.000000) | table field `b` (Float) + +0x01F4 | 18 00 00 00 | UOffset32 | 0x00000018 (24) Loc: +0x020C | offset to field `c` (table) + +0x01F8 | 00 00 00 00 00 D8 8E 40 | double | 0x408ED80000000000 (987.000000) | table field `a` (Double) + +0x0200 | 00 00 00 00 00 00 | uint8_t[6] | ...... | padding + +vtable (AnnotatedBinary.Baz): + +0x0206 | 06 00 | uint16_t | 0x0006 (6) | size of this vtable + +0x0208 | 06 00 | uint16_t | 0x0006 (6) | size of referring table + +0x020A | 05 00 | VOffset16 | 0x0005 (5) | offset to field `meal` (id: 0) + +table (AnnotatedBinary.Baz): + +0x020C | 06 00 00 00 | SOffset32 | 0x00000006 (6) Loc: +0x0206 | offset to vtable + +0x0210 | 00 | uint8_t[1] | . | padding + +0x0211 | 03 | uint8_t | 0x03 (3) | table field `meal` (Byte) + +vtable (AnnotatedBinary.Bar): + +0x0212 | 0A 00 | uint16_t | 0x000A (10) | size of this vtable + +0x0214 | 18 00 | uint16_t | 0x0018 (24) | size of referring table + +0x0216 | 0C 00 | VOffset16 | 0x000C (12) | offset to field `a` (id: 0) + +0x0218 | 04 00 | VOffset16 | 0x0004 (4) | offset to field `b` (id: 1) + +0x021A | 08 00 | VOffset16 | 0x0008 (8) | offset to field `c` (id: 2) + +table (AnnotatedBinary.Bar): + +0x021C | 0A 00 00 00 | SOffset32 | 0x0000000A (10) Loc: +0x0212 | offset to vtable + +0x0220 | 00 00 E4 43 | float | 0x43E40000 (456.000000) | table field `b` (Float) + +0x0224 | 10 00 00 00 | UOffset32 | 0x00000010 (16) Loc: +0x0234 | offset to field `c` (table) + +0x0228 | 00 00 00 00 00 C0 5E 40 | double | 0x405EC00000000000 (123.000000) | table field `a` (Double) + +0x0230 | 00 00 00 00 | uint8_t[4] | .... | padding + +table (AnnotatedBinary.Baz): + +0x0234 | A2 FF FF FF | SOffset32 | 0xFFFFFFA2 (-94) Loc: +0x0292 | offset to vtable + +0x0238 | 00 00 00 | uint8_t[3] | ... | padding + +0x023B | 01 | uint8_t | 0x01 (1) | table field `meal` (Byte) + +string (AnnotatedBinary.Foo.name): + +0x023C | 2F 00 00 00 | uint32_t | 0x0000002F (47) | length of string + +0x0240 | 54 68 69 73 20 69 73 20 | char[47] | This is + +0x0248 | 61 20 6C 6F 6E 67 20 73 | | a long s + +0x0250 | 74 72 69 6E 67 20 74 6F | | tring to + +0x0258 | 20 73 68 6F 77 20 68 6F | | show ho + +0x0260 | 77 20 69 74 20 62 72 65 | | w it bre + +0x0268 | 61 6B 73 20 75 70 2E | | aks up. + +0x026F | 00 | char | 0x00 (0) | string terminator + +unknown (no known references): + +0x0270 | 00 00 0A 00 16 00 0C 00 | ?uint8_t[34] | ........ | WARN: nothing refers to this section. + +0x0278 | 04 00 08 00 0A 00 00 00 | | ........ + +0x0280 | 65 20 71 49 14 00 00 00 | | e qI.... + +0x0288 | C9 76 BE 9F 0C 24 FE 40 | | .v...$.@ + +0x0290 | 00 00 | | .. + +vtable (AnnotatedBinary.Baz): + +0x0292 | 06 00 | uint16_t | 0x0006 (6) | size of this vtable + +0x0294 | 08 00 | uint16_t | 0x0008 (8) | size of referring table + +0x0296 | 07 00 | VOffset16 | 0x0007 (7) | offset to field `meal` (id: 0) + +unknown (no known references): + +0x0298 | 06 00 00 00 00 00 00 01 | ?uint8_t[8] | ........ | WARN: nothing refers to this section. diff --git a/tests/annotated_binary/tests/invalid_vtable_field_offset.bin b/tests/annotated_binary/tests/invalid_vtable_field_offset.bin new file mode 100644 index 0000000000000000000000000000000000000000..e32ce5be8a864b1e83fd70c312e69bd23a5cd5a5 GIT binary patch literal 672 zcmZXR!7BuD6vw~6*}?9hlueSuuQ)geWw#`U!73sYMUl*|%?_JociEei1brBQ zjRd2>C?+tCSNTx}Qw38^Q z=l%=1BIl%!^paM>wx}Xb)=j19!)PQXq3yK=2W%+XTvdhmijhttbx&WOCpiuL_U-xD z7QZHOAY?L2@;?3b+wgB*dC6uNr$L^QzRFM#-z#=AV(-qG-ooKb`RM&ao3}&uWhpi2 z94wVj;%)mc@$vG<#p~JOy=Ak+uhaCRgZxjlPGy{Y)=m3+$z1Z!jFtP9-x1bDIC%|K zHdtBBD(Tnn1@nmR2@=dLbT+rKstd)uOIOV4LMB(zf?L$deA-zr= (Long) + +0x0014 | 08 00 | VOffset16 | 0x0008 (8) | offset to field `meal` (id: 3) + +0x0016 | 10 00 | VOffset16 | 0x0010 (16) | offset to field `bar` (id: 4) + +0x0018 | 14 00 | VOffset16 | 0x0014 (20) | offset to field `home` (id: 5) + +0x001A | 30 00 | VOffset16 | 0x0030 (48) | offset to field `name` (id: 6) + +0x001C | 34 00 | VOffset16 | 0x0034 (52) | offset to field `bars` (id: 7) + +0x001E | 09 00 | VOffset16 | 0x0009 (9) | offset to field `bar_baz_type` (id: 8) + +0x0020 | 38 00 | VOffset16 | 0x0038 (56) | offset to field `bar_baz` (id: 9) + +0x0022 | 3C 00 | VOffset16 | 0x003C (60) | offset to field `accounts` (id: 10) + +0x0024 | 40 00 | VOffset16 | 0x0040 (64) | offset to field `bob` (id: 11) + +0x0026 | 44 00 | VOffset16 | 0x0044 (68) | offset to field `alice` (id: 12) + +0x0028 | 00 00 | VOffset16 | 0x0000 (0) | offset to field `maybe_i32` (id: 13) (Int) + +0x002A | 00 00 | VOffset16 | 0x0000 (0) | offset to field `default_i32` (id: 14) (Int) + +0x002C | 48 00 | VOffset16 | 0x0048 (72) | offset to field `just_i32` (id: 15) + +0x002E | 4C 00 | VOffset16 | 0x004C (76) | offset to field `names` (id: 16) + +0x0030 | 50 00 | VOffset16 | 0x0050 (80) | offset to field `points_of_interest` (id: 17) + +0x0032 | 54 00 | VOffset16 | 0x0054 (84) | offset to field `foobars_type` (id: 18) + +0x0034 | 58 00 | VOffset16 | 0x0058 (88) | offset to field `foobars` (id: 19) + +0x0036 | 0A 00 | VOffset16 | 0x000A (10) | offset to field `measurement_type` (id: 20) + +0x0038 | 5C 00 | VOffset16 | 0x005C (92) | offset to field `measurement` (id: 21) + +0x003A | 0B 00 | VOffset16 | 0x000B (11) | offset to field `anything_type` (id: 22) + +0x003C | 60 00 | VOffset16 | 0x0060 (96) | offset to field `anything` (id: 23) + +0x003E | 00 00 | VOffset16 | 0x0000 (0) | offset to field `temperature` (id: 24) (Float) + +0x0040 | 00 00 | VOffset16 | 0x0000 (0) | offset to field `teetotaler` (id: 25) (Obj) + +0x0042 | 64 00 | VOffset16 | 0x0064 (100) | offset to field `charlie` (id: 26) + +root_table (AnnotatedBinary.Foo): + +0x0044 | 3A 00 00 00 | SOffset32 | 0x0000003A (58) Loc: +0x000A | offset to vtable + +0x0048 | 00 00 00 | uint8_t[3] | ... | padding + +0x004B | 01 | uint8_t | 0x01 (1) | table field `healthy` (Bool) + +0x004C | 02 | uint8_t | 0x02 (2) | table field `meal` (Byte) + +0x004D | 02 | UType8 | 0x02 (2) | table field `bar_baz_type` (UType) + +0x004E | 01 | UType8 | 0x01 (1) | table field `measurement_type` (UType) + +0x004F | 01 | UType8 | 0x01 (1) | table field `anything_type` (UType) + +0x0050 | D2 04 00 00 | uint32_t | 0x000004D2 (1234) | table field `counter` (Int) + +0x0054 | 28 02 00 00 | UOffset32 | 0x00000228 (552) Loc: +0x027C | offset to field `bar` (table) + +0x0058 | 01 00 00 00 | uint32_t | 0x00000001 (1) | struct field `AnnotatedBinary.Building.floors` (Int) + +0x005C | 02 00 00 00 | uint32_t | 0x00000002 (2) | struct field `AnnotatedBinary.Building.doors` (Int) + +0x0060 | 0C 00 00 00 | uint32_t | 0x0000000C (12) | struct field `AnnotatedBinary.Building.windows` (Int) + +0x0064 | 0A 00 00 00 | uint32_t | 0x0000000A (10) | array field `AnnotatedBinary.Dimension.values[0]` (Int) + +0x0068 | 0C 00 00 00 | uint32_t | 0x0000000C (12) | array field `AnnotatedBinary.Dimension.values[1]` (Int) + +0x006C | 14 00 00 00 | uint32_t | 0x00000014 (20) | array field `AnnotatedBinary.Dimension.values[2]` (Int) + +0x0070 | 01 | uint8_t | 0x01 (1) | struct field `AnnotatedBinary.Tolerance.width` (UByte) + +0x0071 | 02 | uint8_t | 0x02 (2) | struct field `AnnotatedBinary.Tolerance.width` (UByte) + +0x0072 | 03 | uint8_t | 0x03 (3) | struct field `AnnotatedBinary.Tolerance.width` (UByte) + +0x0073 | 00 | uint8_t[1] | . | padding + +0x0074 | C8 01 00 00 | UOffset32 | 0x000001C8 (456) Loc: +0x023C | offset to field `name` (string) + +0x0078 | 5C 01 00 00 | UOffset32 | 0x0000015C (348) Loc: +0x01D4 | offset to field `bars` (vector) + +0x007C | 50 01 00 00 | UOffset32 | 0x00000150 (336) Loc: +0x01CC | offset to field `bar_baz` (union of type `Baz`) + +0x0080 | 34 01 00 00 | UOffset32 | 0x00000134 (308) Loc: +0x01B4 | offset to field `accounts` (vector) + +0x0084 | 24 01 00 00 | UOffset32 | 0x00000124 (292) Loc: +0x01A8 | offset to field `bob` (string) + +0x0088 | 14 01 00 00 | UOffset32 | 0x00000114 (276) Loc: +0x019C | offset to field `alice` (string) + +0x008C | 0D 00 00 00 | uint32_t | 0x0000000D (13) | table field `just_i32` (Int) + +0x0090 | DC 00 00 00 | UOffset32 | 0x000000DC (220) Loc: +0x016C | offset to field `names` (vector) + +0x0094 | A0 00 00 00 | UOffset32 | 0x000000A0 (160) Loc: +0x0134 | offset to field `points_of_interest` (vector) + +0x0098 | 94 00 00 00 | UOffset32 | 0x00000094 (148) Loc: +0x012C | offset to field `foobars_type` (vector) + +0x009C | 38 00 00 00 | UOffset32 | 0x00000038 (56) Loc: +0x00D4 | offset to field `foobars` (vector) + +0x00A0 | 33 00 00 00 | UOffset32 | 0x00000033 (51) Loc: +0x00D3 | offset to field `measurement` (union of type `Tolerance`) + +0x00A4 | 1C 00 00 00 | UOffset32 | 0x0000001C (28) Loc: +0x00C0 | offset to field `anything` (union of type `Bar`) + +0x00A8 | 04 00 00 00 | UOffset32 | 0x00000004 (4) Loc: +0x00AC | offset to field `charlie` (string) + +0x00AC | 05 00 00 00 61 6C 69 63 | uint8_t[500] | ....alic | padding + +0x00B4 | 65 00 00 00 08 00 13 00 | | e....... + +0x00BC | 08 00 04 00 08 00 00 00 | | ........ + +0x00C4 | 00 80 23 44 00 00 00 00 | | ..#D.... + +0x00CC | 00 10 74 40 00 00 00 05 | | ..t@.... + +0x00D4 | 03 00 00 00 34 00 00 00 | | ....4... + +0x00DC | 2C 00 00 00 04 00 00 00 | | ,....... + +0x00E4 | D2 FE FF FF 00 80 23 44 | | ......#D + +0x00EC | 10 00 00 00 00 00 00 00 | | ........ + +0x00F4 | 00 D8 8E 40 00 00 00 00 | | ...@.... + +0x00FC | 6A FE FF FF 00 00 00 03 | | j....... + +0x0104 | 04 00 04 00 04 00 00 00 | | ........ + +0x010C | FA FE FF FF 00 00 E4 43 | | .......C + +0x0114 | 10 00 00 00 00 00 00 00 | | ........ + +0x011C | 00 C0 5E 40 00 00 00 00 | | ..^@.... + +0x0124 | 92 FE FF FF 00 00 00 01 | | ........ + +0x012C | 03 00 00 00 01 02 01 00 | | ........ + +0x0134 | 03 00 00 00 33 33 33 33 | | ....3333 + +0x013C | 33 A3 45 40 7E 57 04 FF | | 3.E@~W.. + +0x0144 | 5B 87 53 C0 8D F0 F6 20 | | [.S.... + +0x014C | 04 B6 42 40 9F 77 63 41 | | ..B@.wcA + +0x0154 | 61 85 5E C0 8F 35 23 83 | | a.^..5#. + +0x015C | DC 35 4B C0 F6 97 DD 93 | | .5K..... + +0x0164 | 87 C5 0A 40 00 00 00 00 | | ...@.... + +0x016C | 03 00 00 00 20 00 00 00 | | .... ... + +0x0174 | 14 00 00 00 04 00 00 00 | | ........ + +0x017C | 07 00 00 00 63 68 61 72 | | ....char + +0x0184 | 6C 69 65 00 03 00 00 00 | | lie..... + +0x018C | 62 6F 62 00 05 00 00 00 | | bob..... + +0x0194 | 61 6C 69 63 65 00 00 00 | | alice... + +0x019C | 07 00 00 00 63 68 61 72 | | ....char + +0x01A4 | 6C 69 65 00 07 00 00 00 | | lie..... + +0x01AC | 63 68 61 72 6C 69 65 00 | | charlie. + +0x01B4 | 09 00 00 00 09 00 08 00 | | ........ + +0x01BC | 07 00 01 00 02 00 03 00 | | ........ + +0x01C4 | 06 00 05 00 04 00 00 00 | | ........ + +0x01CC | 3A FF FF FF 00 00 00 03 | | :....... + +0x01D4 | 02 00 00 00 44 00 00 00 | | ....D... + +0x01DC | 10 00 00 00 00 00 0A 00 | | ........ + +0x01E4 | 1A 00 0C 00 04 00 08 00 | | ........ + +0x01EC | 0A 00 00 00 00 80 23 44 | | ......#D + +0x01F4 | 18 00 00 00 00 00 00 00 | | ........ + +0x01FC | 00 D8 8E 40 00 00 00 00 | | ...@.... + +0x0204 | 00 00 06 00 06 00 05 00 | | ........ + +0x020C | 06 00 00 00 00 03 0A 00 | | ........ + +0x0214 | 18 00 0C 00 04 00 08 00 | | ........ + +0x021C | 0A 00 00 00 00 00 E4 43 | | .......C + +0x0224 | 10 00 00 00 00 00 00 00 | | ........ + +0x022C | 00 C0 5E 40 00 00 00 00 | | ..^@.... + +0x0234 | A2 FF FF FF 00 00 00 01 | | ........ + +0x023C | 2F 00 00 00 54 68 69 73 | | /...This + +0x0244 | 20 69 73 20 61 20 6C 6F | | is a lo + +0x024C | 6E 67 20 73 74 72 69 6E | | ng strin + +0x0254 | 67 20 74 6F 20 73 68 6F | | g to sho + +0x025C | 77 20 68 6F 77 20 69 74 | | w how it + +0x0264 | 20 62 72 65 61 6B 73 20 | | breaks + +0x026C | 75 70 2E 00 00 00 0A 00 | | up...... + +0x0274 | 16 00 0C 00 04 00 08 00 | | ........ + +0x027C | 0A 00 00 00 65 20 71 49 | | ....e qI + +0x0284 | 14 00 00 00 C9 76 BE 9F | | .....v.. + +0x028C | 0C 24 FE 40 00 00 06 00 | | .$.@.... + +0x0294 | 08 00 07 00 06 00 00 00 | | ........ + +0x029C | 00 00 00 01 | | .... + +string (AnnotatedBinary.Foo.charlie): + +0x00AC | 05 00 00 00 | uint32_t | 0x00000005 (5) | length of string + +0x00B0 | 61 6C 69 63 65 | char[5] | alice + +0x00B5 | 00 | char | 0x00 (0) | string terminator + +padding: + +0x00B6 | 00 00 | uint8_t[2] | .. | padding + +vtable (AnnotatedBinary.Bar): + +0x00B8 | 08 00 | uint16_t | 0x0008 (8) | size of this vtable + +0x00BA | 13 00 | uint16_t | 0x0013 (19) | size of referring table + +0x00BC | 08 00 | VOffset16 | 0x0008 (8) | offset to field `a` (id: 0) + +0x00BE | 04 00 | VOffset16 | 0x0004 (4) | offset to field `b` (id: 1) + +table (AnnotatedBinary.Bar): + +0x00C0 | 08 00 00 00 | SOffset32 | 0x00000008 (8) Loc: +0x00B8 | offset to vtable + +0x00C4 | 00 80 23 44 | float | 0x44238000 (654.000000) | table field `b` (Float) + +0x00C8 | 00 00 00 00 00 10 74 40 | double | 0x4074100000000000 (321.000000) | table field `a` (Double) + +0x00D0 | 00 00 00 | uint8_t[3] | ... | padding + +union (AnnotatedBinary.Tolerance.measurement): + +0x00D3 | 05 | uint8_t | 0x05 (5) | struct field `AnnotatedBinary.Tolerance.width` (UByte) + +vector (AnnotatedBinary.Foo.foobars): + +0x00D4 | 03 00 00 00 | uint32_t | 0x00000003 (3) | length of vector (# items) + +0x00D8 | 34 00 00 00 | UOffset32 | 0x00000034 (52) Loc: +0x010C | offset to union[0] (`Bar`) + +0x00DC | 2C 00 00 00 | UOffset32 | 0x0000002C (44) Loc: +0x0108 | offset to union[1] (`Baz`) + +0x00E0 | 04 00 00 00 | UOffset32 | 0x00000004 (4) Loc: +0x00E4 | offset to union[2] (`Bar`) + +table (AnnotatedBinary.Bar): + +0x00E4 | D2 FE FF FF | SOffset32 | 0xFFFFFED2 (-302) Loc: +0x0212 | offset to vtable + +0x00E8 | 00 80 23 44 | float | 0x44238000 (654.000000) | table field `b` (Float) + +0x00EC | 10 00 00 00 | UOffset32 | 0x00000010 (16) Loc: +0x00FC | offset to field `c` (table) + +0x00F0 | 00 00 00 00 00 D8 8E 40 | double | 0x408ED80000000000 (987.000000) | table field `a` (Double) + +0x00F8 | 00 00 00 00 | uint8_t[4] | .... | padding + +table (AnnotatedBinary.Baz): + +0x00FC | 6A FE FF FF | SOffset32 | 0xFFFFFE6A (-406) Loc: +0x0292 | offset to vtable + +0x0100 | 00 00 00 | uint8_t[3] | ... | padding + +0x0103 | 03 | uint8_t | 0x03 (3) | table field `meal` (Byte) + +vtable (AnnotatedBinary.Baz): + +0x0104 | 04 00 | uint16_t | 0x0004 (4) | size of this vtable + +0x0106 | 04 00 | uint16_t | 0x0004 (4) | size of referring table + +table (AnnotatedBinary.Baz): + +0x0108 | 04 00 00 00 | SOffset32 | 0x00000004 (4) Loc: +0x0104 | offset to vtable + +table (AnnotatedBinary.Bar): + +0x010C | FA FE FF FF | SOffset32 | 0xFFFFFEFA (-262) Loc: +0x0212 | offset to vtable + +0x0110 | 00 00 E4 43 | float | 0x43E40000 (456.000000) | table field `b` (Float) + +0x0114 | 10 00 00 00 | UOffset32 | 0x00000010 (16) Loc: +0x0124 | offset to field `c` (table) + +0x0118 | 00 00 00 00 00 C0 5E 40 | double | 0x405EC00000000000 (123.000000) | table field `a` (Double) + +0x0120 | 00 00 00 00 | uint8_t[4] | .... | padding + +table (AnnotatedBinary.Baz): + +0x0124 | 92 FE FF FF | SOffset32 | 0xFFFFFE92 (-366) Loc: +0x0292 | offset to vtable + +0x0128 | 00 00 00 | uint8_t[3] | ... | padding + +0x012B | 01 | uint8_t | 0x01 (1) | table field `meal` (Byte) + +vector (AnnotatedBinary.Foo.foobars_type): + +0x012C | 03 00 00 00 | uint32_t | 0x00000003 (3) | length of vector (# items) + +0x0130 | 01 | UType8 | 0x01 (1) | value[0] + +0x0131 | 02 | UType8 | 0x02 (2) | value[1] + +0x0132 | 01 | UType8 | 0x01 (1) | value[2] + +vector (AnnotatedBinary.Foo.points_of_interest): + +0x0134 | 03 00 00 00 | uint32_t | 0x00000003 (3) | length of vector (# items) + +0x0138 | 33 33 33 33 33 A3 45 40 | double | 0x4045A33333333333 (43.275000) | struct field `AnnotatedBinary.Location.latitude` (Double) + +0x0140 | 7E 57 04 FF 5B 87 53 C0 | double | 0xC053875BFF04577E (-78.114990) | struct field `AnnotatedBinary.Location.longitude` (Double) + +0x0148 | 8D F0 F6 20 04 B6 42 40 | double | 0x4042B60420F6F08D (37.422001) | struct field `AnnotatedBinary.Location.latitude` (Double) + +0x0150 | 9F 77 63 41 61 85 5E C0 | double | 0xC05E85614163779F (-122.084061) | struct field `AnnotatedBinary.Location.longitude` (Double) + +0x0158 | 8F 35 23 83 DC 35 4B C0 | double | 0xC04B35DC8323358F (-54.420792) | struct field `AnnotatedBinary.Location.latitude` (Double) + +0x0160 | F6 97 DD 93 87 C5 0A 40 | double | 0x400AC58793DD97F6 (3.346450) | struct field `AnnotatedBinary.Location.longitude` (Double) + +padding: + +0x0168 | 00 00 00 00 | uint8_t[4] | .... | padding + +vector (AnnotatedBinary.Foo.names): + +0x016C | 03 00 00 00 | uint32_t | 0x00000003 (3) | length of vector (# items) + +0x0170 | 20 00 00 00 | UOffset32 | 0x00000020 (32) Loc: +0x0190 | offset to string[0] + +0x0174 | 14 00 00 00 | UOffset32 | 0x00000014 (20) Loc: +0x0188 | offset to string[1] + +0x0178 | 04 00 00 00 | UOffset32 | 0x00000004 (4) Loc: +0x017C | offset to string[2] + +string (AnnotatedBinary.Foo.names): + +0x017C | 07 00 00 00 | uint32_t | 0x00000007 (7) | length of string + +0x0180 | 63 68 61 72 6C 69 65 | char[7] | charlie + +0x0187 | 00 | char | 0x00 (0) | string terminator + +string (AnnotatedBinary.Foo.names): + +0x0188 | 03 00 00 00 | uint32_t | 0x00000003 (3) | length of string + +0x018C | 62 6F 62 | char[3] | bob + +0x018F | 00 | char | 0x00 (0) | string terminator + +string (AnnotatedBinary.Foo.names): + +0x0190 | 05 00 00 00 | uint32_t | 0x00000005 (5) | length of string + +0x0194 | 61 6C 69 63 65 | char[5] | alice + +0x0199 | 00 | char | 0x00 (0) | string terminator + +padding: + +0x019A | 00 00 | uint8_t[2] | .. | padding + +string (AnnotatedBinary.Foo.alice): + +0x019C | 07 00 00 00 | uint32_t | 0x00000007 (7) | length of string + +0x01A0 | 63 68 61 72 6C 69 65 | char[7] | charlie + +0x01A7 | 00 | char | 0x00 (0) | string terminator + +string (AnnotatedBinary.Foo.bob): + +0x01A8 | 07 00 00 00 | uint32_t | 0x00000007 (7) | length of string + +0x01AC | 63 68 61 72 6C 69 65 | char[7] | charlie + +0x01B3 | 00 | char | 0x00 (0) | string terminator + +vector (AnnotatedBinary.Foo.accounts): + +0x01B4 | 09 00 00 00 | uint32_t | 0x00000009 (9) | length of vector (# items) + +0x01B8 | 09 00 | uint16_t | 0x0009 (9) | value[0] + +0x01BA | 08 00 | uint16_t | 0x0008 (8) | value[1] + +0x01BC | 07 00 | uint16_t | 0x0007 (7) | value[2] + +0x01BE | 01 00 | uint16_t | 0x0001 (1) | value[3] + +0x01C0 | 02 00 | uint16_t | 0x0002 (2) | value[4] + +0x01C2 | 03 00 | uint16_t | 0x0003 (3) | value[5] + +0x01C4 | 06 00 | uint16_t | 0x0006 (6) | value[6] + +0x01C6 | 05 00 | uint16_t | 0x0005 (5) | value[7] + +0x01C8 | 04 00 | uint16_t | 0x0004 (4) | value[8] + +padding: + +0x01CA | 00 00 | uint8_t[2] | .. | padding + +table (AnnotatedBinary.Baz): + +0x01CC | 3A FF FF FF | SOffset32 | 0xFFFFFF3A (-198) Loc: +0x0292 | offset to vtable + +0x01D0 | 00 00 00 | uint8_t[3] | ... | padding + +0x01D3 | 03 | uint8_t | 0x03 (3) | table field `meal` (Byte) + +vector (AnnotatedBinary.Foo.bars): + +0x01D4 | 02 00 00 00 | uint32_t | 0x00000002 (2) | length of vector (# items) + +0x01D8 | 44 00 00 00 | UOffset32 | 0x00000044 (68) Loc: +0x021C | offset to table[0] + +0x01DC | 10 00 00 00 | UOffset32 | 0x00000010 (16) Loc: +0x01EC | offset to table[1] + +padding: + +0x01E0 | 00 00 | uint8_t[2] | .. | padding + +vtable (AnnotatedBinary.Bar): + +0x01E2 | 0A 00 | uint16_t | 0x000A (10) | size of this vtable + +0x01E4 | 1A 00 | uint16_t | 0x001A (26) | size of referring table + +0x01E6 | 0C 00 | VOffset16 | 0x000C (12) | offset to field `a` (id: 0) + +0x01E8 | 04 00 | VOffset16 | 0x0004 (4) | offset to field `b` (id: 1) + +0x01EA | 08 00 | VOffset16 | 0x0008 (8) | offset to field `c` (id: 2) + +table (AnnotatedBinary.Bar): + +0x01EC | 0A 00 00 00 | SOffset32 | 0x0000000A (10) Loc: +0x01E2 | offset to vtable + +0x01F0 | 00 80 23 44 | float | 0x44238000 (654.000000) | table field `b` (Float) + +0x01F4 | 18 00 00 00 | UOffset32 | 0x00000018 (24) Loc: +0x020C | offset to field `c` (table) + +0x01F8 | 00 00 00 00 00 D8 8E 40 | double | 0x408ED80000000000 (987.000000) | table field `a` (Double) + +0x0200 | 00 00 00 00 00 00 | uint8_t[6] | ...... | padding + +vtable (AnnotatedBinary.Baz): + +0x0206 | 06 00 | uint16_t | 0x0006 (6) | size of this vtable + +0x0208 | 06 00 | uint16_t | 0x0006 (6) | size of referring table + +0x020A | 05 00 | VOffset16 | 0x0005 (5) | offset to field `meal` (id: 0) + +table (AnnotatedBinary.Baz): + +0x020C | 06 00 00 00 | SOffset32 | 0x00000006 (6) Loc: +0x0206 | offset to vtable + +0x0210 | 00 | uint8_t[1] | . | padding + +0x0211 | 03 | uint8_t | 0x03 (3) | table field `meal` (Byte) + +vtable (AnnotatedBinary.Bar): + +0x0212 | 0A 00 | uint16_t | 0x000A (10) | size of this vtable + +0x0214 | 18 00 | uint16_t | 0x0018 (24) | size of referring table + +0x0216 | 0C 00 | VOffset16 | 0x000C (12) | offset to field `a` (id: 0) + +0x0218 | 04 00 | VOffset16 | 0x0004 (4) | offset to field `b` (id: 1) + +0x021A | 08 00 | VOffset16 | 0x0008 (8) | offset to field `c` (id: 2) + +table (AnnotatedBinary.Bar): + +0x021C | 0A 00 00 00 | SOffset32 | 0x0000000A (10) Loc: +0x0212 | offset to vtable + +0x0220 | 00 00 E4 43 | float | 0x43E40000 (456.000000) | table field `b` (Float) + +0x0224 | 10 00 00 00 | UOffset32 | 0x00000010 (16) Loc: +0x0234 | offset to field `c` (table) + +0x0228 | 00 00 00 00 00 C0 5E 40 | double | 0x405EC00000000000 (123.000000) | table field `a` (Double) + +0x0230 | 00 00 00 00 | uint8_t[4] | .... | padding + +table (AnnotatedBinary.Baz): + +0x0234 | A2 FF FF FF | SOffset32 | 0xFFFFFFA2 (-94) Loc: +0x0292 | offset to vtable + +0x0238 | 00 00 00 | uint8_t[3] | ... | padding + +0x023B | 01 | uint8_t | 0x01 (1) | table field `meal` (Byte) + +string (AnnotatedBinary.Foo.name): + +0x023C | 2F 00 00 00 | uint32_t | 0x0000002F (47) | length of string + +0x0240 | 54 68 69 73 20 69 73 20 | char[47] | This is + +0x0248 | 61 20 6C 6F 6E 67 20 73 | | a long s + +0x0250 | 74 72 69 6E 67 20 74 6F | | tring to + +0x0258 | 20 73 68 6F 77 20 68 6F | | show ho + +0x0260 | 77 20 69 74 20 62 72 65 | | w it bre + +0x0268 | 61 6B 73 20 75 70 2E | | aks up. + +0x026F | 00 | char | 0x00 (0) | string terminator + +padding: + +0x0270 | 00 00 | uint8_t[2] | .. | padding + +vtable (AnnotatedBinary.Bar): + +0x0272 | 0A 00 | uint16_t | 0x000A (10) | size of this vtable + +0x0274 | 16 00 | uint16_t | 0x0016 (22) | size of referring table + +0x0276 | 0C 00 | VOffset16 | 0x000C (12) | offset to field `a` (id: 0) + +0x0278 | 04 00 | VOffset16 | 0x0004 (4) | offset to field `b` (id: 1) + +0x027A | 08 00 | VOffset16 | 0x0008 (8) | offset to field `c` (id: 2) + +table (AnnotatedBinary.Bar): + +0x027C | 0A 00 00 00 | SOffset32 | 0x0000000A (10) Loc: +0x0272 | offset to vtable + +0x0280 | 65 20 71 49 | float | 0x49712065 (987654.312500) | table field `b` (Float) + +0x0284 | 14 00 00 00 | UOffset32 | 0x00000014 (20) Loc: +0x0298 | offset to field `c` (table) + +0x0288 | C9 76 BE 9F 0C 24 FE 40 | double | 0x40FE240C9FBE76C9 (123456.789000) | table field `a` (Double) + +0x0290 | 00 00 | uint8_t[2] | .. | padding + +vtable (AnnotatedBinary.Baz): + +0x0292 | 06 00 | uint16_t | 0x0006 (6) | size of this vtable + +0x0294 | 08 00 | uint16_t | 0x0008 (8) | size of referring table + +0x0296 | 07 00 | VOffset16 | 0x0007 (7) | offset to field `meal` (id: 0) + +table (AnnotatedBinary.Baz): + +0x0298 | 06 00 00 00 | SOffset32 | 0x00000006 (6) Loc: +0x0292 | offset to vtable + +0x029C | 00 00 00 | uint8_t[3] | ... | padding + +0x029F | 01 | uint8_t | 0x01 (1) | table field `meal` (Byte) diff --git a/tests/annotated_binary/tests/invalid_vtable_ref_table_size.bin b/tests/annotated_binary/tests/invalid_vtable_ref_table_size.bin new file mode 100644 index 0000000000000000000000000000000000000000..6b5024224fa854267b005b8552d414988ba7e56d GIT binary patch literal 672 zcmZXR&nrYx6vw~!>cPQBx*K7PnYf2xX=ui-%D}D2gI^GbZzx3^RkBlw^fMSrY$) zrDmhpT3N932UuBHc)sU7Y2@@i@4S2NIp^K;y-5HA6BCm_A3QID8m?;*MGW1DBaB}3 z!$y)(UO)5`S->vYyB7MghrqLkc&=+Goy>_-Q%gY>ADSja+CWj_AvaUJ|ebuoP= z>lQU1N9XeEE4o-JxOAnwE@tyPT5wA`RmeDNMZLAr$qEaN75y`Mb5!(r+`hYvw0+rf L7MaXH3+4U>S{7^k literal 0 HcmV?d00001 diff --git a/tests/annotated_binary/tests/invalid_vtable_ref_table_size_short.afb b/tests/annotated_binary/tests/invalid_vtable_ref_table_size_short.afb new file mode 100644 index 000000000..25fc973e6 --- /dev/null +++ b/tests/annotated_binary/tests/invalid_vtable_ref_table_size_short.afb @@ -0,0 +1,297 @@ +// Annotated Flatbuffer Binary +// +// Schema file: annotated_binary.fbs +// Binary file: tests/invalid_vtable_ref_table_size_short.bin + +header: + +0x0000 | 44 00 00 00 | UOffset32 | 0x00000044 (68) Loc: +0x0044 | offset to root table `AnnotatedBinary.Foo` + +0x0004 | 41 4E 4E 4F | char[4] | ANNO | File Identifier + +padding: + +0x0008 | 00 00 | uint8_t[2] | .. | padding + +vtable (AnnotatedBinary.Foo): + +0x000A | 3A 00 | uint16_t | 0x003A (58) | size of this vtable + +0x000C | 01 00 | uint16_t | 0x0001 (1) | ERROR: size of referring table. Size of table is smaller than the minimum 4 bytes + +0x000E | 0C 00 | VOffset16 | 0x000C (12) | offset to field `counter` (id: 0) + +0x0010 | 07 00 | VOffset16 | 0x0007 (7) | offset to field `healthy` (id: 1) + +0x0012 | 00 00 | VOffset16 | 0x0000 (0) | offset to field `level` (id: 2) (Long) + +0x0014 | 08 00 | VOffset16 | 0x0008 (8) | offset to field `meal` (id: 3) + +0x0016 | 10 00 | VOffset16 | 0x0010 (16) | offset to field `bar` (id: 4) + +0x0018 | 14 00 | VOffset16 | 0x0014 (20) | offset to field `home` (id: 5) + +0x001A | 30 00 | VOffset16 | 0x0030 (48) | offset to field `name` (id: 6) + +0x001C | 34 00 | VOffset16 | 0x0034 (52) | offset to field `bars` (id: 7) + +0x001E | 09 00 | VOffset16 | 0x0009 (9) | offset to field `bar_baz_type` (id: 8) + +0x0020 | 38 00 | VOffset16 | 0x0038 (56) | offset to field `bar_baz` (id: 9) + +0x0022 | 3C 00 | VOffset16 | 0x003C (60) | offset to field `accounts` (id: 10) + +0x0024 | 40 00 | VOffset16 | 0x0040 (64) | offset to field `bob` (id: 11) + +0x0026 | 44 00 | VOffset16 | 0x0044 (68) | offset to field `alice` (id: 12) + +0x0028 | 00 00 | VOffset16 | 0x0000 (0) | offset to field `maybe_i32` (id: 13) (Int) + +0x002A | 00 00 | VOffset16 | 0x0000 (0) | offset to field `default_i32` (id: 14) (Int) + +0x002C | 48 00 | VOffset16 | 0x0048 (72) | offset to field `just_i32` (id: 15) + +0x002E | 4C 00 | VOffset16 | 0x004C (76) | offset to field `names` (id: 16) + +0x0030 | 50 00 | VOffset16 | 0x0050 (80) | offset to field `points_of_interest` (id: 17) + +0x0032 | 54 00 | VOffset16 | 0x0054 (84) | offset to field `foobars_type` (id: 18) + +0x0034 | 58 00 | VOffset16 | 0x0058 (88) | offset to field `foobars` (id: 19) + +0x0036 | 0A 00 | VOffset16 | 0x000A (10) | offset to field `measurement_type` (id: 20) + +0x0038 | 5C 00 | VOffset16 | 0x005C (92) | offset to field `measurement` (id: 21) + +0x003A | 0B 00 | VOffset16 | 0x000B (11) | offset to field `anything_type` (id: 22) + +0x003C | 60 00 | VOffset16 | 0x0060 (96) | offset to field `anything` (id: 23) + +0x003E | 00 00 | VOffset16 | 0x0000 (0) | offset to field `temperature` (id: 24) (Float) + +0x0040 | 00 00 | VOffset16 | 0x0000 (0) | offset to field `teetotaler` (id: 25) (Obj) + +0x0042 | 64 00 | VOffset16 | 0x0064 (100) | offset to field `charlie` (id: 26) + +root_table (AnnotatedBinary.Foo): + +0x0044 | 3A 00 00 00 | SOffset32 | 0x0000003A (58) Loc: +0x000A | offset to vtable + +0x0048 | 00 00 00 | uint8_t[3] | ... | padding + +0x004B | 01 | uint8_t | 0x01 (1) | table field `healthy` (Bool) + +0x004C | 02 | uint8_t | 0x02 (2) | table field `meal` (Byte) + +0x004D | 02 | UType8 | 0x02 (2) | table field `bar_baz_type` (UType) + +0x004E | 01 | UType8 | 0x01 (1) | table field `measurement_type` (UType) + +0x004F | 01 | UType8 | 0x01 (1) | table field `anything_type` (UType) + +0x0050 | D2 04 00 00 | uint32_t | 0x000004D2 (1234) | table field `counter` (Int) + +0x0054 | 28 02 00 00 | UOffset32 | 0x00000228 (552) Loc: +0x027C | offset to field `bar` (table) + +0x0058 | 01 00 00 00 | uint32_t | 0x00000001 (1) | struct field `AnnotatedBinary.Building.floors` (Int) + +0x005C | 02 00 00 00 | uint32_t | 0x00000002 (2) | struct field `AnnotatedBinary.Building.doors` (Int) + +0x0060 | 0C 00 00 00 | uint32_t | 0x0000000C (12) | struct field `AnnotatedBinary.Building.windows` (Int) + +0x0064 | 0A 00 00 00 | uint32_t | 0x0000000A (10) | array field `AnnotatedBinary.Dimension.values[0]` (Int) + +0x0068 | 0C 00 00 00 | uint32_t | 0x0000000C (12) | array field `AnnotatedBinary.Dimension.values[1]` (Int) + +0x006C | 14 00 00 00 | uint32_t | 0x00000014 (20) | array field `AnnotatedBinary.Dimension.values[2]` (Int) + +0x0070 | 01 | uint8_t | 0x01 (1) | struct field `AnnotatedBinary.Tolerance.width` (UByte) + +0x0071 | 02 | uint8_t | 0x02 (2) | struct field `AnnotatedBinary.Tolerance.width` (UByte) + +0x0072 | 03 | uint8_t | 0x03 (3) | struct field `AnnotatedBinary.Tolerance.width` (UByte) + +0x0073 | 00 | uint8_t[1] | . | padding + +0x0074 | C8 01 00 00 | UOffset32 | 0x000001C8 (456) Loc: +0x023C | offset to field `name` (string) + +0x0078 | 5C 01 00 00 | UOffset32 | 0x0000015C (348) Loc: +0x01D4 | offset to field `bars` (vector) + +0x007C | 50 01 00 00 | UOffset32 | 0x00000150 (336) Loc: +0x01CC | offset to field `bar_baz` (union of type `Baz`) + +0x0080 | 34 01 00 00 | UOffset32 | 0x00000134 (308) Loc: +0x01B4 | offset to field `accounts` (vector) + +0x0084 | 24 01 00 00 | UOffset32 | 0x00000124 (292) Loc: +0x01A8 | offset to field `bob` (string) + +0x0088 | 14 01 00 00 | UOffset32 | 0x00000114 (276) Loc: +0x019C | offset to field `alice` (string) + +0x008C | 0D 00 00 00 | uint32_t | 0x0000000D (13) | table field `just_i32` (Int) + +0x0090 | DC 00 00 00 | UOffset32 | 0x000000DC (220) Loc: +0x016C | offset to field `names` (vector) + +0x0094 | A0 00 00 00 | UOffset32 | 0x000000A0 (160) Loc: +0x0134 | offset to field `points_of_interest` (vector) + +0x0098 | 94 00 00 00 | UOffset32 | 0x00000094 (148) Loc: +0x012C | offset to field `foobars_type` (vector) + +0x009C | 38 00 00 00 | UOffset32 | 0x00000038 (56) Loc: +0x00D4 | offset to field `foobars` (vector) + +0x00A0 | 33 00 00 00 | UOffset32 | 0x00000033 (51) Loc: +0x00D3 | offset to field `measurement` (union of type `Tolerance`) + +0x00A4 | 1C 00 00 00 | UOffset32 | 0x0000001C (28) Loc: +0x00C0 | offset to field `anything` (union of type `Bar`) + +0x00A8 | 04 00 00 00 | UOffset32 | 0x00000004 (4) Loc: +0x00AC | offset to field `charlie` (string) + +string (AnnotatedBinary.Foo.charlie): + +0x00AC | 05 00 00 00 | uint32_t | 0x00000005 (5) | length of string + +0x00B0 | 61 6C 69 63 65 | char[5] | alice + +0x00B5 | 00 | char | 0x00 (0) | string terminator + +padding: + +0x00B6 | 00 00 | uint8_t[2] | .. | padding + +vtable (AnnotatedBinary.Bar): + +0x00B8 | 08 00 | uint16_t | 0x0008 (8) | size of this vtable + +0x00BA | 13 00 | uint16_t | 0x0013 (19) | size of referring table + +0x00BC | 08 00 | VOffset16 | 0x0008 (8) | offset to field `a` (id: 0) + +0x00BE | 04 00 | VOffset16 | 0x0004 (4) | offset to field `b` (id: 1) + +table (AnnotatedBinary.Bar): + +0x00C0 | 08 00 00 00 | SOffset32 | 0x00000008 (8) Loc: +0x00B8 | offset to vtable + +0x00C4 | 00 80 23 44 | float | 0x44238000 (654.000000) | table field `b` (Float) + +0x00C8 | 00 00 00 00 00 10 74 40 | double | 0x4074100000000000 (321.000000) | table field `a` (Double) + +0x00D0 | 00 00 00 | uint8_t[3] | ... | padding + +union (AnnotatedBinary.Tolerance.measurement): + +0x00D3 | 05 | uint8_t | 0x05 (5) | struct field `AnnotatedBinary.Tolerance.width` (UByte) + +vector (AnnotatedBinary.Foo.foobars): + +0x00D4 | 03 00 00 00 | uint32_t | 0x00000003 (3) | length of vector (# items) + +0x00D8 | 34 00 00 00 | UOffset32 | 0x00000034 (52) Loc: +0x010C | offset to union[0] (`Bar`) + +0x00DC | 2C 00 00 00 | UOffset32 | 0x0000002C (44) Loc: +0x0108 | offset to union[1] (`Baz`) + +0x00E0 | 04 00 00 00 | UOffset32 | 0x00000004 (4) Loc: +0x00E4 | offset to union[2] (`Bar`) + +table (AnnotatedBinary.Bar): + +0x00E4 | D2 FE FF FF | SOffset32 | 0xFFFFFED2 (-302) Loc: +0x0212 | offset to vtable + +0x00E8 | 00 80 23 44 | float | 0x44238000 (654.000000) | table field `b` (Float) + +0x00EC | 10 00 00 00 | UOffset32 | 0x00000010 (16) Loc: +0x00FC | offset to field `c` (table) + +0x00F0 | 00 00 00 00 00 D8 8E 40 | double | 0x408ED80000000000 (987.000000) | table field `a` (Double) + +0x00F8 | 00 00 00 00 | uint8_t[4] | .... | padding + +table (AnnotatedBinary.Baz): + +0x00FC | 6A FE FF FF | SOffset32 | 0xFFFFFE6A (-406) Loc: +0x0292 | offset to vtable + +0x0100 | 00 00 00 | uint8_t[3] | ... | padding + +0x0103 | 03 | uint8_t | 0x03 (3) | table field `meal` (Byte) + +vtable (AnnotatedBinary.Baz): + +0x0104 | 04 00 | uint16_t | 0x0004 (4) | size of this vtable + +0x0106 | 04 00 | uint16_t | 0x0004 (4) | size of referring table + +table (AnnotatedBinary.Baz): + +0x0108 | 04 00 00 00 | SOffset32 | 0x00000004 (4) Loc: +0x0104 | offset to vtable + +table (AnnotatedBinary.Bar): + +0x010C | FA FE FF FF | SOffset32 | 0xFFFFFEFA (-262) Loc: +0x0212 | offset to vtable + +0x0110 | 00 00 E4 43 | float | 0x43E40000 (456.000000) | table field `b` (Float) + +0x0114 | 10 00 00 00 | UOffset32 | 0x00000010 (16) Loc: +0x0124 | offset to field `c` (table) + +0x0118 | 00 00 00 00 00 C0 5E 40 | double | 0x405EC00000000000 (123.000000) | table field `a` (Double) + +0x0120 | 00 00 00 00 | uint8_t[4] | .... | padding + +table (AnnotatedBinary.Baz): + +0x0124 | 92 FE FF FF | SOffset32 | 0xFFFFFE92 (-366) Loc: +0x0292 | offset to vtable + +0x0128 | 00 00 00 | uint8_t[3] | ... | padding + +0x012B | 01 | uint8_t | 0x01 (1) | table field `meal` (Byte) + +vector (AnnotatedBinary.Foo.foobars_type): + +0x012C | 03 00 00 00 | uint32_t | 0x00000003 (3) | length of vector (# items) + +0x0130 | 01 | UType8 | 0x01 (1) | value[0] + +0x0131 | 02 | UType8 | 0x02 (2) | value[1] + +0x0132 | 01 | UType8 | 0x01 (1) | value[2] + +vector (AnnotatedBinary.Foo.points_of_interest): + +0x0134 | 03 00 00 00 | uint32_t | 0x00000003 (3) | length of vector (# items) + +0x0138 | 33 33 33 33 33 A3 45 40 | double | 0x4045A33333333333 (43.275000) | struct field `AnnotatedBinary.Location.latitude` (Double) + +0x0140 | 7E 57 04 FF 5B 87 53 C0 | double | 0xC053875BFF04577E (-78.114990) | struct field `AnnotatedBinary.Location.longitude` (Double) + +0x0148 | 8D F0 F6 20 04 B6 42 40 | double | 0x4042B60420F6F08D (37.422001) | struct field `AnnotatedBinary.Location.latitude` (Double) + +0x0150 | 9F 77 63 41 61 85 5E C0 | double | 0xC05E85614163779F (-122.084061) | struct field `AnnotatedBinary.Location.longitude` (Double) + +0x0158 | 8F 35 23 83 DC 35 4B C0 | double | 0xC04B35DC8323358F (-54.420792) | struct field `AnnotatedBinary.Location.latitude` (Double) + +0x0160 | F6 97 DD 93 87 C5 0A 40 | double | 0x400AC58793DD97F6 (3.346450) | struct field `AnnotatedBinary.Location.longitude` (Double) + +padding: + +0x0168 | 00 00 00 00 | uint8_t[4] | .... | padding + +vector (AnnotatedBinary.Foo.names): + +0x016C | 03 00 00 00 | uint32_t | 0x00000003 (3) | length of vector (# items) + +0x0170 | 20 00 00 00 | UOffset32 | 0x00000020 (32) Loc: +0x0190 | offset to string[0] + +0x0174 | 14 00 00 00 | UOffset32 | 0x00000014 (20) Loc: +0x0188 | offset to string[1] + +0x0178 | 04 00 00 00 | UOffset32 | 0x00000004 (4) Loc: +0x017C | offset to string[2] + +string (AnnotatedBinary.Foo.names): + +0x017C | 07 00 00 00 | uint32_t | 0x00000007 (7) | length of string + +0x0180 | 63 68 61 72 6C 69 65 | char[7] | charlie + +0x0187 | 00 | char | 0x00 (0) | string terminator + +string (AnnotatedBinary.Foo.names): + +0x0188 | 03 00 00 00 | uint32_t | 0x00000003 (3) | length of string + +0x018C | 62 6F 62 | char[3] | bob + +0x018F | 00 | char | 0x00 (0) | string terminator + +string (AnnotatedBinary.Foo.names): + +0x0190 | 05 00 00 00 | uint32_t | 0x00000005 (5) | length of string + +0x0194 | 61 6C 69 63 65 | char[5] | alice + +0x0199 | 00 | char | 0x00 (0) | string terminator + +padding: + +0x019A | 00 00 | uint8_t[2] | .. | padding + +string (AnnotatedBinary.Foo.alice): + +0x019C | 07 00 00 00 | uint32_t | 0x00000007 (7) | length of string + +0x01A0 | 63 68 61 72 6C 69 65 | char[7] | charlie + +0x01A7 | 00 | char | 0x00 (0) | string terminator + +string (AnnotatedBinary.Foo.bob): + +0x01A8 | 07 00 00 00 | uint32_t | 0x00000007 (7) | length of string + +0x01AC | 63 68 61 72 6C 69 65 | char[7] | charlie + +0x01B3 | 00 | char | 0x00 (0) | string terminator + +vector (AnnotatedBinary.Foo.accounts): + +0x01B4 | 09 00 00 00 | uint32_t | 0x00000009 (9) | length of vector (# items) + +0x01B8 | 09 00 | uint16_t | 0x0009 (9) | value[0] + +0x01BA | 08 00 | uint16_t | 0x0008 (8) | value[1] + +0x01BC | 07 00 | uint16_t | 0x0007 (7) | value[2] + +0x01BE | 01 00 | uint16_t | 0x0001 (1) | value[3] + +0x01C0 | 02 00 | uint16_t | 0x0002 (2) | value[4] + +0x01C2 | 03 00 | uint16_t | 0x0003 (3) | value[5] + +0x01C4 | 06 00 | uint16_t | 0x0006 (6) | value[6] + +0x01C6 | 05 00 | uint16_t | 0x0005 (5) | value[7] + +0x01C8 | 04 00 | uint16_t | 0x0004 (4) | value[8] + +padding: + +0x01CA | 00 00 | uint8_t[2] | .. | padding + +table (AnnotatedBinary.Baz): + +0x01CC | 3A FF FF FF | SOffset32 | 0xFFFFFF3A (-198) Loc: +0x0292 | offset to vtable + +0x01D0 | 00 00 00 | uint8_t[3] | ... | padding + +0x01D3 | 03 | uint8_t | 0x03 (3) | table field `meal` (Byte) + +vector (AnnotatedBinary.Foo.bars): + +0x01D4 | 02 00 00 00 | uint32_t | 0x00000002 (2) | length of vector (# items) + +0x01D8 | 44 00 00 00 | UOffset32 | 0x00000044 (68) Loc: +0x021C | offset to table[0] + +0x01DC | 10 00 00 00 | UOffset32 | 0x00000010 (16) Loc: +0x01EC | offset to table[1] + +padding: + +0x01E0 | 00 00 | uint8_t[2] | .. | padding + +vtable (AnnotatedBinary.Bar): + +0x01E2 | 0A 00 | uint16_t | 0x000A (10) | size of this vtable + +0x01E4 | 1A 00 | uint16_t | 0x001A (26) | size of referring table + +0x01E6 | 0C 00 | VOffset16 | 0x000C (12) | offset to field `a` (id: 0) + +0x01E8 | 04 00 | VOffset16 | 0x0004 (4) | offset to field `b` (id: 1) + +0x01EA | 08 00 | VOffset16 | 0x0008 (8) | offset to field `c` (id: 2) + +table (AnnotatedBinary.Bar): + +0x01EC | 0A 00 00 00 | SOffset32 | 0x0000000A (10) Loc: +0x01E2 | offset to vtable + +0x01F0 | 00 80 23 44 | float | 0x44238000 (654.000000) | table field `b` (Float) + +0x01F4 | 18 00 00 00 | UOffset32 | 0x00000018 (24) Loc: +0x020C | offset to field `c` (table) + +0x01F8 | 00 00 00 00 00 D8 8E 40 | double | 0x408ED80000000000 (987.000000) | table field `a` (Double) + +0x0200 | 00 00 00 00 00 00 | uint8_t[6] | ...... | padding + +vtable (AnnotatedBinary.Baz): + +0x0206 | 06 00 | uint16_t | 0x0006 (6) | size of this vtable + +0x0208 | 06 00 | uint16_t | 0x0006 (6) | size of referring table + +0x020A | 05 00 | VOffset16 | 0x0005 (5) | offset to field `meal` (id: 0) + +table (AnnotatedBinary.Baz): + +0x020C | 06 00 00 00 | SOffset32 | 0x00000006 (6) Loc: +0x0206 | offset to vtable + +0x0210 | 00 | uint8_t[1] | . | padding + +0x0211 | 03 | uint8_t | 0x03 (3) | table field `meal` (Byte) + +vtable (AnnotatedBinary.Bar): + +0x0212 | 0A 00 | uint16_t | 0x000A (10) | size of this vtable + +0x0214 | 18 00 | uint16_t | 0x0018 (24) | size of referring table + +0x0216 | 0C 00 | VOffset16 | 0x000C (12) | offset to field `a` (id: 0) + +0x0218 | 04 00 | VOffset16 | 0x0004 (4) | offset to field `b` (id: 1) + +0x021A | 08 00 | VOffset16 | 0x0008 (8) | offset to field `c` (id: 2) + +table (AnnotatedBinary.Bar): + +0x021C | 0A 00 00 00 | SOffset32 | 0x0000000A (10) Loc: +0x0212 | offset to vtable + +0x0220 | 00 00 E4 43 | float | 0x43E40000 (456.000000) | table field `b` (Float) + +0x0224 | 10 00 00 00 | UOffset32 | 0x00000010 (16) Loc: +0x0234 | offset to field `c` (table) + +0x0228 | 00 00 00 00 00 C0 5E 40 | double | 0x405EC00000000000 (123.000000) | table field `a` (Double) + +0x0230 | 00 00 00 00 | uint8_t[4] | .... | padding + +table (AnnotatedBinary.Baz): + +0x0234 | A2 FF FF FF | SOffset32 | 0xFFFFFFA2 (-94) Loc: +0x0292 | offset to vtable + +0x0238 | 00 00 00 | uint8_t[3] | ... | padding + +0x023B | 01 | uint8_t | 0x01 (1) | table field `meal` (Byte) + +string (AnnotatedBinary.Foo.name): + +0x023C | 2F 00 00 00 | uint32_t | 0x0000002F (47) | length of string + +0x0240 | 54 68 69 73 20 69 73 20 | char[47] | This is + +0x0248 | 61 20 6C 6F 6E 67 20 73 | | a long s + +0x0250 | 74 72 69 6E 67 20 74 6F | | tring to + +0x0258 | 20 73 68 6F 77 20 68 6F | | show ho + +0x0260 | 77 20 69 74 20 62 72 65 | | w it bre + +0x0268 | 61 6B 73 20 75 70 2E | | aks up. + +0x026F | 00 | char | 0x00 (0) | string terminator + +padding: + +0x0270 | 00 00 | uint8_t[2] | .. | padding + +vtable (AnnotatedBinary.Bar): + +0x0272 | 0A 00 | uint16_t | 0x000A (10) | size of this vtable + +0x0274 | 16 00 | uint16_t | 0x0016 (22) | size of referring table + +0x0276 | 0C 00 | VOffset16 | 0x000C (12) | offset to field `a` (id: 0) + +0x0278 | 04 00 | VOffset16 | 0x0004 (4) | offset to field `b` (id: 1) + +0x027A | 08 00 | VOffset16 | 0x0008 (8) | offset to field `c` (id: 2) + +table (AnnotatedBinary.Bar): + +0x027C | 0A 00 00 00 | SOffset32 | 0x0000000A (10) Loc: +0x0272 | offset to vtable + +0x0280 | 65 20 71 49 | float | 0x49712065 (987654.312500) | table field `b` (Float) + +0x0284 | 14 00 00 00 | UOffset32 | 0x00000014 (20) Loc: +0x0298 | offset to field `c` (table) + +0x0288 | C9 76 BE 9F 0C 24 FE 40 | double | 0x40FE240C9FBE76C9 (123456.789000) | table field `a` (Double) + +0x0290 | 00 00 | uint8_t[2] | .. | padding + +vtable (AnnotatedBinary.Baz): + +0x0292 | 06 00 | uint16_t | 0x0006 (6) | size of this vtable + +0x0294 | 08 00 | uint16_t | 0x0008 (8) | size of referring table + +0x0296 | 07 00 | VOffset16 | 0x0007 (7) | offset to field `meal` (id: 0) + +table (AnnotatedBinary.Baz): + +0x0298 | 06 00 00 00 | SOffset32 | 0x00000006 (6) Loc: +0x0292 | offset to vtable + +0x029C | 00 00 00 | uint8_t[3] | ... | padding + +0x029F | 01 | uint8_t | 0x01 (1) | table field `meal` (Byte) diff --git a/tests/annotated_binary/tests/invalid_vtable_ref_table_size_short.bin b/tests/annotated_binary/tests/invalid_vtable_ref_table_size_short.bin new file mode 100644 index 0000000000000000000000000000000000000000..e1db9b790f143c8deddb566ec87110ee380b9c35 GIT binary patch literal 672 zcmZXR!7D^j6vn^%=3(Zcrc9b-amy?$gfdF9co;>*6h)D|8IyTThMB=mO0q(sEQ$ZY zQnOKPtt{C21FS48jPJZBjhx=^op;YY=e&Eqn*cC4IXMONL!kk6Tn7(PdV8rVK-=ClhElz+M0yJA&E1kI*Y4fCp|akR*wd7>STZ z?!S;La!&e44{0TAiyGqO+;oOMh$dnZ+FqM~z;MatswTi!oOBSWd-|$WBqz*o&z_HM z@v9OC0w%L0@6%hq4gcnq7j1@d>gOrxs|*G4Jz_T__U^1%nLnH^AH9EQ^LEI-+({2Q z2aDyC-nRXh-tqFs#p~JOy=Ak+tJCzNgZxjlPG_A$&dqpxseJ0sjMe+q-yzn8IC&ja zHdtB9D(Tl>@#hiU6U3jxLJMy}l#+W89irmJeslmkNRL{H1uR6X^YLGgYyUs0i|I32 zx2X9zI+tHx(Zy21r7PuiF`M7ff?Lw5LdIDu>aC4VR#<4R>Yve@W1`37_T6Pe?8}z3 K$YkDGDEBuyhH3u* literal 0 HcmV?d00001 diff --git a/tests/annotated_binary/tests/invalid_vtable_size.afb b/tests/annotated_binary/tests/invalid_vtable_size.afb new file mode 100644 index 000000000..fce71c00a --- /dev/null +++ b/tests/annotated_binary/tests/invalid_vtable_size.afb @@ -0,0 +1,99 @@ +// Annotated Flatbuffer Binary +// +// Schema file: annotated_binary.fbs +// Binary file: tests/invalid_vtable_size.bin + +header: + +0x0000 | 44 00 00 00 | UOffset32 | 0x00000044 (68) Loc: +0x0044 | offset to root table `AnnotatedBinary.Foo` + +0x0004 | 41 4E 4E 4F | char[4] | ANNO | File Identifier + +padding: + +0x0008 | 00 00 | uint8_t[2] | .. | padding + +vtable (AnnotatedBinary.Foo): + +0x000A | FF FF | uint16_t | 0xFFFF (65535) | ERROR: size of this vtable. Longer than the binary + +unknown (no known references): + +0x000C | 68 00 0C 00 07 00 00 00 | ?uint8_t[660] | h....... | WARN: nothing refers to this section. + +0x0014 | 08 00 10 00 14 00 30 00 | | ......0. + +0x001C | 34 00 09 00 38 00 3C 00 | | 4...8.<. + +0x0024 | 40 00 44 00 00 00 00 00 | | @.D..... + +0x002C | 48 00 4C 00 50 00 54 00 | | H.L.P.T. + +0x0034 | 58 00 0A 00 5C 00 0B 00 | | X...\... + +0x003C | 60 00 00 00 00 00 64 00 | | `.....d. + +0x0044 | 3A 00 00 00 00 00 00 01 | | :....... + +0x004C | 02 02 01 01 D2 04 00 00 | | ........ + +0x0054 | 28 02 00 00 01 00 00 00 | | (....... + +0x005C | 02 00 00 00 0C 00 00 00 | | ........ + +0x0064 | 0A 00 00 00 0C 00 00 00 | | ........ + +0x006C | 14 00 00 00 01 02 03 00 | | ........ + +0x0074 | C8 01 00 00 5C 01 00 00 | | ....\... + +0x007C | 50 01 00 00 34 01 00 00 | | P...4... + +0x0084 | 24 01 00 00 14 01 00 00 | | $....... + +0x008C | 0D 00 00 00 DC 00 00 00 | | ........ + +0x0094 | A0 00 00 00 94 00 00 00 | | ........ + +0x009C | 38 00 00 00 33 00 00 00 | | 8...3... + +0x00A4 | 1C 00 00 00 04 00 00 00 | | ........ + +0x00AC | 05 00 00 00 61 6C 69 63 | | ....alic + +0x00B4 | 65 00 00 00 08 00 13 00 | | e....... + +0x00BC | 08 00 04 00 08 00 00 00 | | ........ + +0x00C4 | 00 80 23 44 00 00 00 00 | | ..#D.... + +0x00CC | 00 10 74 40 00 00 00 05 | | ..t@.... + +0x00D4 | 03 00 00 00 34 00 00 00 | | ....4... + +0x00DC | 2C 00 00 00 04 00 00 00 | | ,....... + +0x00E4 | D2 FE FF FF 00 80 23 44 | | ......#D + +0x00EC | 10 00 00 00 00 00 00 00 | | ........ + +0x00F4 | 00 D8 8E 40 00 00 00 00 | | ...@.... + +0x00FC | 6A FE FF FF 00 00 00 03 | | j....... + +0x0104 | 04 00 04 00 04 00 00 00 | | ........ + +0x010C | FA FE FF FF 00 00 E4 43 | | .......C + +0x0114 | 10 00 00 00 00 00 00 00 | | ........ + +0x011C | 00 C0 5E 40 00 00 00 00 | | ..^@.... + +0x0124 | 92 FE FF FF 00 00 00 01 | | ........ + +0x012C | 03 00 00 00 01 02 01 00 | | ........ + +0x0134 | 03 00 00 00 33 33 33 33 | | ....3333 + +0x013C | 33 A3 45 40 7E 57 04 FF | | 3.E@~W.. + +0x0144 | 5B 87 53 C0 8D F0 F6 20 | | [.S.... + +0x014C | 04 B6 42 40 9F 77 63 41 | | ..B@.wcA + +0x0154 | 61 85 5E C0 8F 35 23 83 | | a.^..5#. + +0x015C | DC 35 4B C0 F6 97 DD 93 | | .5K..... + +0x0164 | 87 C5 0A 40 00 00 00 00 | | ...@.... + +0x016C | 03 00 00 00 20 00 00 00 | | .... ... + +0x0174 | 14 00 00 00 04 00 00 00 | | ........ + +0x017C | 07 00 00 00 63 68 61 72 | | ....char + +0x0184 | 6C 69 65 00 03 00 00 00 | | lie..... + +0x018C | 62 6F 62 00 05 00 00 00 | | bob..... + +0x0194 | 61 6C 69 63 65 00 00 00 | | alice... + +0x019C | 07 00 00 00 63 68 61 72 | | ....char + +0x01A4 | 6C 69 65 00 07 00 00 00 | | lie..... + +0x01AC | 63 68 61 72 6C 69 65 00 | | charlie. + +0x01B4 | 09 00 00 00 09 00 08 00 | | ........ + +0x01BC | 07 00 01 00 02 00 03 00 | | ........ + +0x01C4 | 06 00 05 00 04 00 00 00 | | ........ + +0x01CC | 3A FF FF FF 00 00 00 03 | | :....... + +0x01D4 | 02 00 00 00 44 00 00 00 | | ....D... + +0x01DC | 10 00 00 00 00 00 0A 00 | | ........ + +0x01E4 | 1A 00 0C 00 04 00 08 00 | | ........ + +0x01EC | 0A 00 00 00 00 80 23 44 | | ......#D + +0x01F4 | 18 00 00 00 00 00 00 00 | | ........ + +0x01FC | 00 D8 8E 40 00 00 00 00 | | ...@.... + +0x0204 | 00 00 06 00 06 00 05 00 | | ........ + +0x020C | 06 00 00 00 00 03 0A 00 | | ........ + +0x0214 | 18 00 0C 00 04 00 08 00 | | ........ + +0x021C | 0A 00 00 00 00 00 E4 43 | | .......C + +0x0224 | 10 00 00 00 00 00 00 00 | | ........ + +0x022C | 00 C0 5E 40 00 00 00 00 | | ..^@.... + +0x0234 | A2 FF FF FF 00 00 00 01 | | ........ + +0x023C | 2F 00 00 00 54 68 69 73 | | /...This + +0x0244 | 20 69 73 20 61 20 6C 6F | | is a lo + +0x024C | 6E 67 20 73 74 72 69 6E | | ng strin + +0x0254 | 67 20 74 6F 20 73 68 6F | | g to sho + +0x025C | 77 20 68 6F 77 20 69 74 | | w how it + +0x0264 | 20 62 72 65 61 6B 73 20 | | breaks + +0x026C | 75 70 2E 00 00 00 0A 00 | | up...... + +0x0274 | 16 00 0C 00 04 00 08 00 | | ........ + +0x027C | 0A 00 00 00 65 20 71 49 | | ....e qI + +0x0284 | 14 00 00 00 C9 76 BE 9F | | .....v.. + +0x028C | 0C 24 FE 40 00 00 06 00 | | .$.@.... + +0x0294 | 08 00 07 00 06 00 00 00 | | ........ + +0x029C | 00 00 00 01 | | .... diff --git a/tests/annotated_binary/tests/invalid_vtable_size.bin b/tests/annotated_binary/tests/invalid_vtable_size.bin new file mode 100644 index 0000000000000000000000000000000000000000..fdc7e98f6391a164452010cccd8ebe5dab245618 GIT binary patch literal 672 zcmZXR&nrYx6vw~!>a(YRV+Z;uZ@Fp^TC&-Y|*?MNuSg#$+CoVP=?}lw^fMSrY$) zrDmhpT3N932UuBHc)sU7Y2-Ga`M!JZIp^K;eF*^Z$;m0e^D?MM4fnN(Ac`Ku5Jo=+ zVI#pPFp3FGV;1wUu!uS=`_UB)_zGnhNHlXX*RYAqUxNx1gff(u59Hg{Da{>4Zqk-DcZ&y$=8pZ)cG zY>Tc*90-}rlDtoU|2F)aS6;Fi#%YkJq^~j*M0;i3jM%$#rnhi7Q$BkC(B|!seOXGy zor9(FNnhLkOW%0;<#U*IVNPB{ zmkm}{vr766c)>j4dx8XWSZLu_5U1ojh!4%8vVMF3J4laeiG?gQSLWltAJ@TqR5#OS zGj2ii=jd#1V^tT5d6!bm=|Uz~(t=ym$$Z*bFX-*fE>>7*s_38ATVvwKefyU! Lcah2byU^}$)HZA? literal 0 HcmV?d00001 diff --git a/tests/annotated_binary/tests/invalid_vtable_size_short.afb b/tests/annotated_binary/tests/invalid_vtable_size_short.afb new file mode 100644 index 000000000..9d53c1d6e --- /dev/null +++ b/tests/annotated_binary/tests/invalid_vtable_size_short.afb @@ -0,0 +1,99 @@ +// Annotated Flatbuffer Binary +// +// Schema file: annotated_binary.fbs +// Binary file: tests/invalid_vtable_size_short.bin + +header: + +0x0000 | 44 00 00 00 | UOffset32 | 0x00000044 (68) Loc: +0x0044 | offset to root table `AnnotatedBinary.Foo` + +0x0004 | 41 4E 4E 4F | char[4] | ANNO | File Identifier + +padding: + +0x0008 | 00 00 | uint8_t[2] | .. | padding + +vtable (AnnotatedBinary.Foo): + +0x000A | 01 00 | uint16_t | 0x0001 (1) | ERROR: size of this vtable. Shorter than the minimum 4 bytes + +unknown (no known references): + +0x000C | 68 00 0C 00 07 00 00 00 | ?uint8_t[660] | h....... | WARN: nothing refers to this section. + +0x0014 | 08 00 10 00 14 00 30 00 | | ......0. + +0x001C | 34 00 09 00 38 00 3C 00 | | 4...8.<. + +0x0024 | 40 00 44 00 00 00 00 00 | | @.D..... + +0x002C | 48 00 4C 00 50 00 54 00 | | H.L.P.T. + +0x0034 | 58 00 0A 00 5C 00 0B 00 | | X...\... + +0x003C | 60 00 00 00 00 00 64 00 | | `.....d. + +0x0044 | 3A 00 00 00 00 00 00 01 | | :....... + +0x004C | 02 02 01 01 D2 04 00 00 | | ........ + +0x0054 | 28 02 00 00 01 00 00 00 | | (....... + +0x005C | 02 00 00 00 0C 00 00 00 | | ........ + +0x0064 | 0A 00 00 00 0C 00 00 00 | | ........ + +0x006C | 14 00 00 00 01 02 03 00 | | ........ + +0x0074 | C8 01 00 00 5C 01 00 00 | | ....\... + +0x007C | 50 01 00 00 34 01 00 00 | | P...4... + +0x0084 | 24 01 00 00 14 01 00 00 | | $....... + +0x008C | 0D 00 00 00 DC 00 00 00 | | ........ + +0x0094 | A0 00 00 00 94 00 00 00 | | ........ + +0x009C | 38 00 00 00 33 00 00 00 | | 8...3... + +0x00A4 | 1C 00 00 00 04 00 00 00 | | ........ + +0x00AC | 05 00 00 00 61 6C 69 63 | | ....alic + +0x00B4 | 65 00 00 00 08 00 13 00 | | e....... + +0x00BC | 08 00 04 00 08 00 00 00 | | ........ + +0x00C4 | 00 80 23 44 00 00 00 00 | | ..#D.... + +0x00CC | 00 10 74 40 00 00 00 05 | | ..t@.... + +0x00D4 | 03 00 00 00 34 00 00 00 | | ....4... + +0x00DC | 2C 00 00 00 04 00 00 00 | | ,....... + +0x00E4 | D2 FE FF FF 00 80 23 44 | | ......#D + +0x00EC | 10 00 00 00 00 00 00 00 | | ........ + +0x00F4 | 00 D8 8E 40 00 00 00 00 | | ...@.... + +0x00FC | 6A FE FF FF 00 00 00 03 | | j....... + +0x0104 | 04 00 04 00 04 00 00 00 | | ........ + +0x010C | FA FE FF FF 00 00 E4 43 | | .......C + +0x0114 | 10 00 00 00 00 00 00 00 | | ........ + +0x011C | 00 C0 5E 40 00 00 00 00 | | ..^@.... + +0x0124 | 92 FE FF FF 00 00 00 01 | | ........ + +0x012C | 03 00 00 00 01 02 01 00 | | ........ + +0x0134 | 03 00 00 00 33 33 33 33 | | ....3333 + +0x013C | 33 A3 45 40 7E 57 04 FF | | 3.E@~W.. + +0x0144 | 5B 87 53 C0 8D F0 F6 20 | | [.S.... + +0x014C | 04 B6 42 40 9F 77 63 41 | | ..B@.wcA + +0x0154 | 61 85 5E C0 8F 35 23 83 | | a.^..5#. + +0x015C | DC 35 4B C0 F6 97 DD 93 | | .5K..... + +0x0164 | 87 C5 0A 40 00 00 00 00 | | ...@.... + +0x016C | 03 00 00 00 20 00 00 00 | | .... ... + +0x0174 | 14 00 00 00 04 00 00 00 | | ........ + +0x017C | 07 00 00 00 63 68 61 72 | | ....char + +0x0184 | 6C 69 65 00 03 00 00 00 | | lie..... + +0x018C | 62 6F 62 00 05 00 00 00 | | bob..... + +0x0194 | 61 6C 69 63 65 00 00 00 | | alice... + +0x019C | 07 00 00 00 63 68 61 72 | | ....char + +0x01A4 | 6C 69 65 00 07 00 00 00 | | lie..... + +0x01AC | 63 68 61 72 6C 69 65 00 | | charlie. + +0x01B4 | 09 00 00 00 09 00 08 00 | | ........ + +0x01BC | 07 00 01 00 02 00 03 00 | | ........ + +0x01C4 | 06 00 05 00 04 00 00 00 | | ........ + +0x01CC | 3A FF FF FF 00 00 00 03 | | :....... + +0x01D4 | 02 00 00 00 44 00 00 00 | | ....D... + +0x01DC | 10 00 00 00 00 00 0A 00 | | ........ + +0x01E4 | 1A 00 0C 00 04 00 08 00 | | ........ + +0x01EC | 0A 00 00 00 00 80 23 44 | | ......#D + +0x01F4 | 18 00 00 00 00 00 00 00 | | ........ + +0x01FC | 00 D8 8E 40 00 00 00 00 | | ...@.... + +0x0204 | 00 00 06 00 06 00 05 00 | | ........ + +0x020C | 06 00 00 00 00 03 0A 00 | | ........ + +0x0214 | 18 00 0C 00 04 00 08 00 | | ........ + +0x021C | 0A 00 00 00 00 00 E4 43 | | .......C + +0x0224 | 10 00 00 00 00 00 00 00 | | ........ + +0x022C | 00 C0 5E 40 00 00 00 00 | | ..^@.... + +0x0234 | A2 FF FF FF 00 00 00 01 | | ........ + +0x023C | 2F 00 00 00 54 68 69 73 | | /...This + +0x0244 | 20 69 73 20 61 20 6C 6F | | is a lo + +0x024C | 6E 67 20 73 74 72 69 6E | | ng strin + +0x0254 | 67 20 74 6F 20 73 68 6F | | g to sho + +0x025C | 77 20 68 6F 77 20 69 74 | | w how it + +0x0264 | 20 62 72 65 61 6B 73 20 | | breaks + +0x026C | 75 70 2E 00 00 00 0A 00 | | up...... + +0x0274 | 16 00 0C 00 04 00 08 00 | | ........ + +0x027C | 0A 00 00 00 65 20 71 49 | | ....e qI + +0x0284 | 14 00 00 00 C9 76 BE 9F | | .....v.. + +0x028C | 0C 24 FE 40 00 00 06 00 | | .$.@.... + +0x0294 | 08 00 07 00 06 00 00 00 | | ........ + +0x029C | 00 00 00 01 | | .... diff --git a/tests/annotated_binary/tests/invalid_vtable_size_short.bin b/tests/annotated_binary/tests/invalid_vtable_size_short.bin new file mode 100644 index 0000000000000000000000000000000000000000..435bd742d9caf44f3e695cc029ffc716460620c7 GIT binary patch literal 672 zcmZXR!7D^j6vn^%=3(Zcrc9b-amy?$gfdF9co;>*6h)D|8IyTThMB=mO0q(sEQ$ZY zQnOKPtt{C21FS48jPJZBjojup-@E6YbKX7QO8^+0oSXs_vS>gZ_d$daK{w(Ep$`MF zkzf=U#RQU=!5l0spdL$JbQ%4gLK%iqPbScANH>7Oj$pR05vno*c;MjzNs>5;kqBwz z`3t!s=cJGHkXFLBs3A_yO=qYeR})1;orRSqRlW){X8Xom7yToBkN|w-kmio^M}*rqxTPO-VWK9JLy5^ zV6lAC+qVDGJ6`^{cs)D3w``Vpb($(Z$os_Wbk-^4+>CdY%BTL!Sbbjo9AaIFlh@H@ zgO#