From abe06c6f5a54dd8f98662c70a2894cfacff074a7 Mon Sep 17 00:00:00 2001 From: Marcus Holland-Moritz Date: Sun, 18 May 2025 12:57:23 +0200 Subject: [PATCH] fix(filesystem_parser): more section index discovery checks (gh #264) --- src/reader/internal/filesystem_parser.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/reader/internal/filesystem_parser.cpp b/src/reader/internal/filesystem_parser.cpp index 70b81ab1..6d54a3f8 100644 --- a/src/reader/internal/filesystem_parser.cpp +++ b/src/reader/internal/filesystem_parser.cpp @@ -263,18 +263,22 @@ void filesystem_parser::find_index() { auto section = fs_section(*mm_, index_pos, version_); - if (!section.check_fast(*mm_)) { - return; - } - if (section.type() != section_type::SECTION_INDEX) { return; } + if (section.compression() != compression_type::NONE) { + return; + } + if (section.length() % sizeof(uint64_t) != 0) { return; } + if (!section.check_fast(*mm_)) { + return; + } + auto const section_count = section.length() / sizeof(uint64_t); // 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 index_.clear(); + return; + } + + if ((index_.at(0) & section_offset_mask) != 0) { + index_.clear(); + return; } }