fix(filesystem_parser): more section index discovery checks (gh #264)

This commit is contained in:
Marcus Holland-Moritz 2025-05-18 12:57:23 +02:00 committed by mhx
parent 661b951cfd
commit abe06c6f5a

View File

@ -263,18 +263,22 @@ void filesystem_parser::find_index() {
auto section = fs_section(*mm_, index_pos, version_); auto section = fs_section(*mm_, index_pos, version_);
if (!section.check_fast(*mm_)) {
return;
}
if (section.type() != section_type::SECTION_INDEX) { if (section.type() != section_type::SECTION_INDEX) {
return; return;
} }
if (section.compression() != compression_type::NONE) {
return;
}
if (section.length() % sizeof(uint64_t) != 0) { if (section.length() % sizeof(uint64_t) != 0) {
return; return;
} }
if (!section.check_fast(*mm_)) {
return;
}
auto const section_count = section.length() / sizeof(uint64_t); auto const section_count = section.length() / sizeof(uint64_t);
// at least METADATA_V2_SCHEMA, METADATA_V2, and SECTION_INDEX // at least METADATA_V2_SCHEMA, METADATA_V2, and SECTION_INDEX
@ -298,6 +302,12 @@ void filesystem_parser::find_index() {
})) { })) {
// remove the index again if it is not sorted // remove the index again if it is not sorted
index_.clear(); index_.clear();
return;
}
if ((index_.at(0) & section_offset_mask) != 0) {
index_.clear();
return;
} }
} }