| 169 | } |
| 170 | |
| 171 | bool StrataFileReader::read_section(uint32_t section_id, std::vector<uint8_t>& out, std::string& err) const { |
| 172 | if (section_id >= STRATA_NUM_SECTIONS) { |
| 173 | err = "Invalid section_id"; |
| 174 | return false; |
| 175 | } |
| 176 | const auto& sec = hdr_.sections[section_id]; |
| 177 | // a header whose lengths run past the file would ask for an allocation of that size: say so instead |
| 178 | if (file_size_ != 0 && (sec.file_offset > file_size_ || sec.byte_length > file_size_ - sec.file_offset) && sec.byte_length != 0) { |
| 179 | err = "Section " + std::to_string(section_id) + " extends past the end of the file (truncated file?)"; |
| 180 | return false; |
| 181 | } |
| 182 | out.resize(static_cast<size_t>(sec.byte_length)); |
| 183 | if (sec.byte_length == 0) return true; |
| 184 | return read_at(sec.file_offset, out.data(), out.size(), err); |
| 185 | } |
| 186 | |
| 187 | bool StrataFileReader::read_expert_body(size_t dir_index, std::vector<uint8_t>& out, std::string& err) const { |
| 188 | if (dir_index >= experts_.size()) { |