| 157 | } |
| 158 | |
| 159 | uint64_t BinaryAnnotator::BuildHeader(const uint64_t header_offset) { |
| 160 | uint64_t offset = header_offset; |
| 161 | std::vector<BinaryRegion> regions; |
| 162 | |
| 163 | // If this binary is a size prefixed one, attempt to parse the size. |
| 164 | if (is_size_prefixed_) { |
| 165 | BinaryRegionComment prefix_length_comment; |
| 166 | prefix_length_comment.type = BinaryRegionCommentType::SizePrefix; |
| 167 | |
| 168 | bool has_prefix_value = false; |
| 169 | const auto prefix_length = ReadScalar<uoffset64_t>(offset); |
| 170 | if (*prefix_length <= binary_length_) { |
| 171 | regions.push_back(MakeBinaryRegion(offset, sizeof(uoffset64_t), |
| 172 | BinaryRegionType::Uint64, 0, 0, |
| 173 | prefix_length_comment)); |
| 174 | offset += sizeof(uoffset64_t); |
| 175 | has_prefix_value = true; |
| 176 | } |
| 177 | |
| 178 | if (!has_prefix_value) { |
| 179 | const auto prefix_length = ReadScalar<uoffset_t>(offset); |
| 180 | if (*prefix_length <= binary_length_) { |
| 181 | regions.push_back(MakeBinaryRegion(offset, sizeof(uoffset_t), |
| 182 | BinaryRegionType::Uint32, 0, 0, |
| 183 | prefix_length_comment)); |
| 184 | offset += sizeof(uoffset_t); |
| 185 | has_prefix_value = true; |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | if (!has_prefix_value) { |
| 190 | SetError(prefix_length_comment, BinaryRegionStatus::ERROR); |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | const auto root_table_offset = ReadScalar<uint32_t>(offset); |
| 195 | |
| 196 | if (!root_table_offset.has_value()) { |
| 197 | // This shouldn't occur, since we validate the min size of the buffer |
| 198 | // before. But for completion sake, we shouldn't read passed the binary end. |
| 199 | return std::numeric_limits<uint64_t>::max(); |
| 200 | } |
| 201 | |
| 202 | const auto root_table_loc = offset + *root_table_offset; |
| 203 | |
| 204 | BinaryRegionComment root_offset_comment; |
| 205 | root_offset_comment.type = BinaryRegionCommentType::RootTableOffset; |
| 206 | root_offset_comment.name = schema_->root_table()->name()->str(); |
| 207 | |
| 208 | if (!IsValidOffset(root_table_loc)) { |
| 209 | SetError(root_offset_comment, |
| 210 | BinaryRegionStatus::ERROR_OFFSET_OUT_OF_BINARY); |
| 211 | } |
| 212 | |
| 213 | regions.push_back(MakeBinaryRegion(offset, sizeof(uint32_t), |
| 214 | BinaryRegionType::UOffset, 0, |
| 215 | root_table_loc, root_offset_comment)); |
| 216 | offset += sizeof(uint32_t); |
nothing calls this directly
no test coverage detected