fuzzed binary annotator (#7188)

This commit is contained in:
Derek Bailey
2022-03-25 22:58:15 -07:00
committed by GitHub
parent e2be0c0b06
commit ae4ce72651
20 changed files with 2241 additions and 2094 deletions

View File

@@ -277,6 +277,24 @@ class BinaryAnnotator {
return value < enum_def->values()->size();
}
uint64_t GetElementSize(const reflection::Field *const field) {
if (IsScalar(field->type()->element())) {
return GetTypeSize(field->type()->element());
}
switch (field->type()->element()) {
case reflection::BaseType::Obj: {
auto obj = schema_->objects()->Get(field->type()->index());
return obj->is_struct() ? obj->bytesize() : sizeof(uint32_t);
}
default: return sizeof(uint32_t);
}
}
bool ContainsSection(const uint64_t offset) {
return sections_.find(offset) != sections_.end();
}
// The schema for the binary file
const uint8_t *bfbs_;
const uint64_t bfbs_length_;
@@ -289,9 +307,6 @@ class BinaryAnnotator {
// Map of binary offset to vtables, to dedupe vtables.
std::map<uint64_t, VTable> vtables_;
// A set of binary offset to string sections, to dedupe shared strings.
std::set<uint64_t> strings_;
// The annotated binary sections, index by their absolute offset.
std::map<uint64_t, BinarySection> sections_;
};