diff --git a/src/dwarfs/filesystem_v2.cpp b/src/dwarfs/filesystem_v2.cpp index b309a9d0..8f0e6d5e 100644 --- a/src/dwarfs/filesystem_v2.cpp +++ b/src/dwarfs/filesystem_v2.cpp @@ -19,8 +19,10 @@ * along with dwarfs. If not, see . */ +#include #include #include +#include #include #include #include @@ -66,15 +68,16 @@ class filesystem_parser { break; } - auto ps = mm.as(start); - auto pc = ::memmem(ps, mm.size() - start, magic.data(), magic.size()); + auto ss = mm.span(start); + auto it = std::search( + ss.begin(), ss.end(), + std::boyer_moore_horspool_searcher(magic.begin(), magic.end())); - if (!pc) { + if (it == ss.end()) { break; } - file_off_t pos = start + static_cast(pc) - - static_cast(ps); + file_off_t pos = start + std::distance(ss.begin(), it); if (pos + sizeof(file_header) >= mm.size()) { break; @@ -106,7 +109,7 @@ class filesystem_parser { break; } - ps = mm.as(pos + sh->length + sizeof(section_header_v2)); + auto ps = mm.as(pos + sh->length + sizeof(section_header_v2)); if (::memcmp(ps, magic.data(), magic.size()) == 0 and reinterpret_cast(ps)->number == 1) {